<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../assert/css/font.css" th:href="@{/assert/css/font.css}"/>
    <link rel="stylesheet" href="../../../assert/css/plugin/chosen/chosen.css"
          th:href="@{/assert/css/plugin/chosen/chosen.css}"/>
    <link href="../../../assert/css/animate.min.css" rel="stylesheet" th:href="@{/assert/css/animate.min.css}">
    <link href="../../../assert/css/plugin/toastr/toastr.min.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/toastr/toastr.min.css}">
    <link href="../../../assert/css/plugin/jsTree/themes/default/style.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/jsTree/themes/default/style.css}">
    <link href="../../../assert/js/layui/css/layui.css" rel="stylesheet"
          th:href="@{/assert/js/layui/css/layui.css}" media="all">
    <link href="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css" rel="stylesheet"
          th:href="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css}"/>
    <link href="../../../assert/css/loaders.css" rel="stylesheet"
          th:href="@{/assert/css/loaders.css}">
    <link rel="stylesheet" href="../../../assert/css/bootstrap.min.css" th:href="@{/assert/css/bootstrap.min.css}"/>
    <link rel="stylesheet" href="../../../assert/css/bootstrap-table.css" th:href="@{/assert/css/bootstrap-table.css}"/>
    <link rel="stylesheet" href="../../../assert/css/jquery-ui.css" th:href="@{/assert/css/jquery-ui.css}"/>
    <link rel="stylesheet" href="../../../assert/css/index.css"
          th:href="@{/assert/css/index.css(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"/>
    <style>
        .table_msg {
            width: 100%;
            border: 1px solid #e4eaec;
            padding: 0px 10px;
            position: relative;
            top: 6px;
            background: #ddd;
        }

        .layui-form-switch {
            width: 48px;
        }

        .search_group label.control-label {
            width: 70px;
        }

        .remarkBox .jqx-validator-error-label {
            top: 70px !important;
        }

        label {
            max-width: none;
        }

        .left {
            float: left;
        }

        .right {
            float: left;
        }

        .ceng {
            width: 511px;
            height: 432px;
            line-height: 432px;
            position: absolute;
            top: 40px;
            opacity: .5;
            text-align: center;
            color: #000;
            font-size: 16px;
            border: 1px solid #d2cbcb;
        }
    </style>
</head>
<body class="oneStyle">
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="model_left">
            <!--<h4 class="model_title">质检模型</h4>-->
            <div class="search_box">
                <input type="text" style="width: 174px;padding:1px 5px;" autocomplete="off"><span
                    class="fa fa-search fa_btn"
                    id="searchMenu"></span>
                <span class="fa fa-plus fa_btn hidden" id="addType" title="添加省级信息"></span>
            </div>

            <div id="jstree" class="scrollbar">

            </div>
        </div>
        <div class="model_right">
            <div class="tools_bar">
                <div class="pull-left">
                    <a href="#" class="btn btn-default active" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 隐藏</a>
                    <a href="#" class="btn btn-default active" id="refresh"><i class="fa fa-refresh"></i> 刷新</a>
                    <a href="#" class="btn btn-default active" id="btnAdd" title="添加质检模型"><i class="fa fa-plus"></i> 添加</a>
                    <a href="#" class="btn btn-default active" id="btnEdit" title="编辑质检模型"><i class="fa fa-pencil"></i>
                        编辑</a>
                    <a href="#" class="btn btn-default active" id="btnDel" title="删除质检模型"><i class="fa fa-remove"></i>
                        删除</a>
                    <a href="#" class="btn btn-default active" id="btnCopy" title="复制质检模型"><i class="fa fa-copy"></i> 复制</a>
                    <a href="#" style="margin-left:20px" class="btn btn-default active" id="btnStart" title="上线质检模型"><i
                            class="fa fa-long-arrow-up stateGreen"></i> 上线</a>
                    <a href="#" class="btn btn-default active" id="btnStop" title="下线质检模型"><i
                            class="fa fa-long-arrow-down stateRed"></i> 下线</a>

                </div>
            </div>
            <div class="search on">
                <div class="search_group">
                    <label class="control-label">省份：</label>
                    <div class="control-inline">
                        <select type="text" id="pro" value="" class="form-control search_input"
                                data-code="pro"></select>
                    </div>
                </div>
                <div class="search_group">
                    <label class="control-label">名称：</label>
                    <div class="control-inline">
                        <input type="text" id="modelname" value="" class="form-control search_input" autocomplete="off">
                    </div>
                </div>
                <div class="search_group">
                    <label class="control-label">状态：</label>
                    <div class="control-inline">
                        <select type="text" id="state" value=""
                                class="form-control search_input chosen-select"></select>
                    </div>
                </div>
                <div class="search_group">
                    <label class="control-label">创建人：</label>
                    <div class="control-inline">
                        <input type="text" id="person" value="" class="form-control search_input" autocomplete="off">
                    </div>
                </div>
                <div class="search_group">
                    <label class="control-label">创建时间：</label>
                    <div class="control-inline">
                        <input placeholder="开始日期" class="form-control layer-date search_input" id="start"
                               autocomplete="off"> -
                        <input placeholder="结束日期" class="form-control layer-date search_input" id="end"
                               autocomplete="off">
                    </div>
                </div>
                <div class="search_group hidden">
                    <label class="control-label">包含关键词：</label>
                    <div class="control-inline">
                        <input type="text" id="keyinclude" value="" class="form-control search_input"
                               autocomplete="off">
                    </div>
                </div>
                <div class="search_group">
                    <button id="search" class="btn  btn-primary">查询</button>
                    <button id="searchAll" class="btn  btn-primary">全查询</button>
                    <button id="reset" class="btn  btn-default">重置</button>
                    <button id="export" class="btn  btn-default">导出</button>
                </div>
            </div>
            <table id="myTable"></table>
        </div>
    </div>
</div>
<input type="text" id="classify" value="" class="form-control search_input hidden" autocomplete="off"/>
<!--添加模型-->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:900px !important;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">添加模型</h4>
            </div>
            <div class="modal-body">
                <form method="post" class="form-horizontal" id="addModelForm">
                    <div class="form-group">
                        <div class="form-box">
                            <label for="" class="col-sm-5 control-label"><span class="respan">*</span>省份:</label>
                            <div class="col-sm-7">
                                <select name="provincecode" id="proModal" data-code="pro"></select>
                                <input type="text" class="form-control selectInput" id="proModalAddInput"
                                       autocomplete="off">
                            </div>
                        </div>
                        <div class="form-box">
                            <label for="" class="col-sm-3 control-label"><span class="respan">*</span>质检模型分类:</label>
                            <div class="col-sm-7">
                                <select id="typeModal"></select>
                                <input type="text" id="typeModalAddInput" class="form-control selectInput" name="typeid"
                                       value="" autocomplete="off">

                            </div>
                        </div>

                    </div>
                    <div class="form-group">
                        <div class="form-box">
                            <label for="" class="col-sm-5 control-label"><span class="respan">*</span>质检模型名称:</label>
                            <div class="col-sm-7">
                                <input name="name" id="testName" class="form-control" value="" autocomplete="off"
                                       placeholder="请输入质检模型名称"/>
                            </div>
                        </div>
                        <div class="form-box">
                            <label for="" class="col-sm-3 control-label"><span class="respan">*</span>质检模型分数:</label>
                            <div class="col-sm-7">
                                <input name="fullscore" id="testScore" class="form-control" value=""
                                       autocomplete="off" placeholder="请输入质检模型分数"/>
                            </div>
                        </div>
                    </div>
                    <!--<div class="form-group">-->
                    <!--<label for="" class="col-sm-3 control-label" style="width:21%;">模型执行有效期:</label>-->
                    <!--<div class="col-sm-8">-->
                    <!--<input placeholder="开始日期" class="form-control layer-date search_input" id="start1"-->
                    <!--style="width:230px;" name="createtime" value=""> - -->
                    <!--<input placeholder="结束日期" class="form-control layer-date search_input" id="end1"-->
                    <!--style="width:230px;" name="lastupdatetime" value="">-->
                    <!--</div>-->
                    <!--</div>-->
                    <div class="form-group remarkBox">
                        <label for="" class="col-sm-3 control-label" style="width:21%;">备注:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <textarea name="note" class="form-control" style="height:70px;" id="remarkAdd"
                                      placeholder="最多输入255个字符"></textarea>
                        </div>
                    </div>
                </form>
                <form method="post" class="form-horizontal" id="scoreForm">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label" style="width:21%;">质检规则:</label>
                        <div class="col-sm-8" style="width: 70.6%;" id="addRuleTable">
                            <button class="btn btn-primary" type="button" id="addRule"><i class="fa fa-plus"></i>添加规则
                            </button>
                            <div class="rule_box">
                                <table id="ruleTable"></table>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="save">保存</button>
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
<!--编辑模型-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:900px !important;">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">编辑模型</h4>
            </div>
            <div class="modal-body">
                <form method="post" class="form-horizontal" id="editForm">
                    <div class="form-group">
                        <div class="form-box">
                            <label for="" class="col-sm-5 control-label"><span class="respan">*</span>省份:</label>
                            <div class="col-sm-7">
                                <select name="provincecode" id="proModalEdit" data-code="pro"></select>
                                <input type="text" class="form-control selectInput" id="proModalEditInput"
                                       autocomplete="off">
                            </div>
                        </div>
                        <div class="form-box">
                            <label for="" class="col-sm-3 control-label"><span class="respan">*</span>质检模型分类:</label>
                            <div class="col-sm-7">
                                <select id="modelTypeEdit"></select>
                                <input type="text" id="typeModalEditInput" class="form-control selectInput"
                                       name="typeid" value="" autocomplete="off">
                            </div>
                        </div>

                    </div>
                    <div class="form-group">
                        <div class="form-box">
                            <label for="" class="col-sm-5 control-label"><span class="respan">*</span>质检模型名称:</label>
                            <div class="col-sm-7">
                                <input name="name" id="testNameEdit" class="form-control" value="" autocomplete="off"
                                       placeholder="请输入质检模型名称"/>
                            </div>
                        </div>
                        <div class="form-box">
                            <label for="" class="col-sm-3 control-label"><span class="respan">*</span>质检模型分数:</label>
                            <div class="col-sm-7">
                                <input name="fullscore" id="testScoreEdit" class="form-control" value="100"
                                       autocomplete="off" placeholder="请输入质检模型分数"/>
                            </div>
                        </div>
                    </div>
                    <!--<div class="form-group">-->
                    <!--<label for="" class="col-sm-3 control-label" style="width:21%;">模型执行有效期:</label>-->
                    <!--<div class="col-sm-8">-->
                    <!--<input placeholder="开始日期" class="form-control layer-date search_input" id="start1"-->
                    <!--style="width:230px;" name="createtime" value=""> - -->
                    <!--<input placeholder="结束日期" class="form-control layer-date search_input" id="end1"-->
                    <!--style="width:230px;" name="lastupdatetime" value="">-->
                    <!--</div>-->
                    <!--</div>-->
                    <div class="form-group remarkBox">
                        <label for="" class="col-sm-3 control-label" style="width:21%;">备注:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <textarea name="note" class="form-control" style="height:70px;" id="remarkEdit"
                                      placeholder="最多输入255个字符"></textarea>
                        </div>
                    </div>
                </form>
                <form method="post" class="form-horizontal" id="scoreFormEdit">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label" style="width:21%;">质检规则:</label>
                        <div class="col-sm-8" style="width: 70.6%;" id="ruleBoxEdit">
                            <button class="btn btn-primary" type="button" id="editRule"><i class="fa fa-plus"></i>添加规则
                            </button>
                            <div class="rule_box">
                                <table id="ruleTableEdit"></table>
                            </div>

                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="saveEdit">保存</button>
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
<!--删除确认框-->
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">删除</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align: center;color:#ff0000;margin-bottom:10px;" id="delTextM"></div>
                    <div style="text-align: center">
                        <div>
                            <div class="tipBox"></div>
                        </div>
                        <span class="fa fa-question-circle"></span>
                        <span id="delName"></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="delBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--上线/下线确认框-->
<div class="modal fade" id="startModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">上线</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align: center">
                        <div>
                            <div class="tipBox"></div>
                        </div>
                        <span class="fa fa-question-circle"></span>
                        <span id="type"></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="startBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--复制 确认框-->
<div class="modal fade" id="copyModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:800px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">复制</h4>
            </div>
            <div class="modal-body" style="display: inline-block;">
                <div class="left">
                    <label for="" class="control-label" style="font-weight: bold;">模型分类目录:</label>
                    <div class="search_box">
                        <input type="text" autocomplete="off" style="width: 225px;"><span class="fa fa-search fa_btn"
                                                                                          id="searchMenuCopy"
                                                                                          style="top: -2px;"></span>
                    </div>
                    <div id="jsTreeCopy" class="scrollbar" style="height:400px;width:255px;">

                    </div>
                </div>
                <div class="right" style="width: 510px;">
                    <div class="ceng">请选择没有子分类的节点！</div>
                    <div style="display: none;">
                        <label for="" class="control-label" style="padding-left:127px;font-weight: bold;">原名称:</label>
                        <label for="" class="control-label" style="padding-left:136px;font-weight: bold;">重命名:</label>
                        <form method="post" class="form-horizontal" id="copyForm" style="text-align: center">
                            <ul class="nameList scrollbar" style="height:430px;">
                                <li><input type="text" class="oldName form-control" autocomplete="off"><span
                                        class="fa fa-long-arrow-right"></span><input type="text"
                                                                                     class="newName form-control"
                                                                                     autocomplete="off"></li>
                                <li><input type="text" class="oldName form-control" autocomplete="off"><span
                                        class="fa fa-long-arrow-right"></span><input type="text"
                                                                                     class="newName form-control"
                                                                                     autocomplete="off"></li>
                            </ul>
                        </form>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="copyBtn">确定</button>
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<!--删除分类确认框-->
<div class="modal fade" id="delModalCon" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">删除</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align: center;color:#ff0000;margin-bottom:10px;" id="delText"></div>
                    <div style="text-align: center"><span class="fa fa-question-circle"></span>确定要删除 <span
                            id="delNameCon"></span> 吗？
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="delConBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--添加分类模态框-->
<div class="modal fade" id="addTypeModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post" class="form-horizontal" id="addTypeForm">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">添加分类</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label">省份:</label>
                        <div class="col-sm-8">
                            <select name="provinceid" id="proTypeModal" data-code="pro"></select>
                            <input type="text" class="form-control selectInput" id="proTypeModalAddInput"
                                   autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label">上级分类:</label>
                        <div class="col-sm-8">
                            <select name="provinceid" id="typeParentModal"></select>
                            <input type="text" class="form-control selectInput" id="typeParentModalAddInput"
                                   autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label">分类名称:</label>
                        <div class="col-sm-8">
                            <input type="text" name="name" id="modelTypeName" class="form-control" autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group remarkBox">
                        <label for="" class="col-sm-3 control-label">备注:</label>
                        <div class="col-sm-8">
                            <textarea name="note" class="form-control" style="height:70px;"
                                      id="remarkTypeAdd" placeholder="最多输入255个字符"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="addTypeBtn">保存</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<form action="" id="exportForm" class="hidden" method="post" target="_self">
    <input type="text" id="provincecodeE" name="provincecode">
    <input type="text" id="nameE" name="modelname">
    <input type="text" id="typeidE" name="classify">
    <input type="text" id="stateE" name="state">
    <input type="text" id="startE" name="start">
    <input type="text" id="endE" name="end">
    <input type="text" id="personE" name="person">
</form>
<!--添加规则-->
<div class="modal fade" id="addRuleModel" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:1200px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close closeRuleBox" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">添加规则</h4>
            </div>
            <div class="modal-body" style="height:670px;overflow: hidden;">
                <div class="left" style="width:210px">
                    <div class="search_box">
                        <input type="text" style="width: 174px;padding:3px 5px;" autocomplete="off"><span
                            class="fa fa-search fa_btn"
                            id="searchMenuRule"></span>
                    </div>

                    <div id="jstreeRule" class="scrollbar" style="height:610px">

                    </div>
                </div>
                <div class="right" style="width:955px">
                    <div class="search on" style="top:0;margin-bottom:10px;">
                        <div class="search_group">
                            <label class="control-label">规则名称：</label>
                            <div class="control-inline">
                                <input type="text" id="rulename" value="" class="form-control search_input"
                                       autocomplete="off">
                            </div>
                        </div>
                        <div class="search_group">
                            <label class="control-label">规则分类：</label>
                            <div class="control-inline">
                                <input type="text" id="classifyRule" value="" class="form-control search_input"
                                       autocomplete="off"
                                       readonly/>
                            </div>
                        </div>
                        <div class="search_group">
                            <label class="control-label">规则属性：</label>
                            <div class="control-inline">
                                <select type="text" id="ruleattributes" value=""
                                        class="form-control search_input chosen-select"></select>
                            </div>
                        </div>
                        <div class="search_group">
                            <label class="control-label">发布状态：</label>
                            <div class="control-inline">
                                <select type="text" id="stateRule" value=""
                                        class="form-control search_input chosen-select"></select>
                            </div>
                        </div>
                        <div class="search_group">
                            <label class="control-label">分值属性：</label>
                            <div class="control-inline">
                                <select type="text" id="scoreFlag" value=""
                                        class="form-control search_input chosen-select"></select>
                            </div>
                        </div>
                        <div class="search_group">
                            <label class="control-label">创建人员：</label>
                            <div class="control-inline">
                                <input type="text" id="personRule" value="" class="form-control search_input"
                                       autocomplete="off">
                            </div>
                        </div>
                        <div class="search_group">
                            <label class="control-label">创建时间：</label>
                            <div class="control-inline">
                                <input placeholder="开始日期" class="form-control layer-date search_input" id="startRule"
                                       autocomplete="off"> -
                                <input placeholder="结束日期" class="form-control layer-date search_input" id="endRule"
                                       autocomplete="off">
                            </div>
                        </div>
                        <div class="search_group">
                            <label class="control-label">上线时间：</label>
                            <div class="control-inline">
                                <input placeholder="开始日期" class="form-control layer-date search_input" id="startS"
                                       autocomplete="off"> -
                                <input placeholder="结束日期" class="form-control layer-date search_input" id="endS"
                                       autocomplete="off">
                            </div>
                        </div>
                        <div class="search_group">
                            <label class="control-label">更新时间：</label>
                            <div class="control-inline">
                                <input placeholder="开始日期" class="form-control layer-date search_input" id="startUp"
                                       autocomplete="off"> -
                                <input placeholder="结束日期" class="form-control layer-date search_input" id="endUp"
                                       autocomplete="off">
                            </div>
                        </div>
                        <div class="search_group hidden">
                            <label class="control-label">致命性：</label>
                            <div class="control-inline">
                                <select type="text" id="rulefatal" value=""
                                        class="form-control search_input chosen-select"></select>
                            </div>
                        </div>
                        <div class="search_group">
                            <button id="searchRule" class="btn  btn-primary">查询</button>
                            <button id="searchAllRule" class="btn  btn-primary">全查询</button>
                            <button id="resetRule" class="btn  btn-default">重置</button>
                        </div>
                    </div>
                    <table id="tableRule"></table>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="addRuleBtn">确定</button>
                <button type="button" class="btn btn-white closeRuleBox" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<!--下线确认框-->
<div class="modal fade" id="stopCon" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">下线</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align: center">
                        <span class="fa fa-question-circle"></span>
                        <span id="stopConTip"></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="stopConBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<a id="basePath" th:href="@{/}"></a>
<input type="text" id="idservice" class="hidden">
<script src="../../../assert/js/jquery.js" th:src="@{/assert/js/jquery.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/bootstrap.min.js" th:src="@{/assert/js/bootstrap.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/plugin/bootstrap-table/bootstrap-table.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/bootstrap-table.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/plugin/bootstrap-table/bootstrap-table-mobile.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/bootstrap-table-mobile.min.js}"></script>
<script src="../../../assert/js/plugin/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<script src="../../../assert/js/plugin/toastr/toastr.min.js"
        th:src="@{/assert/js/plugin/toastr/toastr.min.js}"></script>
<script src="../../../assert/js/base.js"
        th:src="@{/assert/js/base.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/jquery-ui.min.js" th:src="@{/assert/js/jquery-ui.min.js}"></script>
<script src="../../../assert/js/plugin/layer/laydate/laydate.js"
        th:src="@{/assert/js/plugin/layer/laydate/laydate.js}"></script>
<script src="../../../assert/js/changeTime.js"
        th:src="@{/assert/js/changeTime.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/plugin/jsTree/jstree.min.js"
        th:src="@{/assert/js/plugin/jsTree/jstree.min.js}"></script>
<script src="../../../assert/js/plugin/chosen/chosen.jquery.js"
        th:src="@{/assert/js/plugin/chosen/chosen.jquery.js}"></script>
<script src="../../../assert/js/layui/layui.js" th:src="@{/assert/js/layui/layui.js}"></script>
<script src="../../../assert/js/common.js"
        th:src="@{/assert/js/common.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxcore.js"
        th:src="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxcore.js}"></script>
<script src="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxvalidator.js"
        th:src="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxvalidator.js}"></script>
<script>
    //项目名称
    var basePath = $("#basePath").attr("href");
    var json = [];
    //    模型表格
    var TableInit = function () {
        var oTableInit = new Object();
        var url = basePath + "rest/model/select/byMutiConditionAndPagenationAndMutilTable";
        var height = ($(window).height() -$(".tools_bar").height()-9-$(".search").height()-40);
        //初始化Table
        oTableInit.Init = function () {
            $('#myTable').bootstrapTable("destroy");
            $('#myTable').bootstrapTable({
                url: url,         //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                sortable: true,                     //是否启用排序
                sortOrder: "desc",                   //排序方式
                sortName: "lastupdatetime", //排序方式
                height:height,
                responseHandler: function (res) {
                    tools.tableData = res.data;
                    return {
                        "total": res.count,//总页数
                        "rows": res.data   //数据
                    };
                },
                pagination: true, // 是否显示分页（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                contentType: "application/x-www-form-urlencoded",
                strictSearch: true,
                showColumns: false,                  //是否显示所有的列
                showRefresh: false,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                uniqueId: "no",                     //每一行的唯一标识，一般为主键列
                showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: true,
                cellStyle: {
                    css: {"background-color": "#fff"}
                },//是否显示父子表
                queryParams: function (params) {
                    var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,   //页面大小
                        offset: params.offset,  //偏移量
                        sortName: this.sortName,
                        sortOrder: this.sortOrder,
                        provincecode: $("#pro").val(),  //
                        classify: $("#classify").val(), //分类
                        person: bs.getXInY(tools.seatAllArr, "id", "userName", $.trim($("#person").val())), //创建人
                        modelname: $.trim($("#modelname").val()),//名称
                        keyinclude: $("#keyinclude").val(),//关键词
                        state: $("#state").val(),//状态
                        start: $("#start").val(),//开始日期
                        end: $("#end").val() //结束日期
                    };
                    return temp;
                },
                columns: [
                    {
                        checkbox: true, // 显示一个勾选框
                        align: 'center' // 居中显示
                    },
                    {
                        align: "center",
                        halign: "center",
                        title: '序号',//标题  可不加
                        width: 60,
                        field: 'number',
                        formatter: function (value, row, index) {
                            var getOptions = $("#myTable").bootstrapTable('getOptions');
                            var pagenum = getOptions.pageNumber;
                            var pagesize = getOptions.pageSize;
                            var st = (pagenum - 1) * pagesize;
                            return (st + index + 1) + "";
                        }
                    },
                    {
                        align: "center",
                        halign: "center",
                        title: '模型ID',
                        width: 60,
                        field: 'id',
                        visible: false
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'provincecode',
                        title: '省份',
                        sortable: true,
                        formatter: function (value, row, index) {
                            return row.areaname;
                        }
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'name',
                        sortable: true,
                        title: '质检模型名称'
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'fullscore',
                        sortable: true,
                        title: '质检模型分数'
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'typeid',
                        sortable: true,
                        title: '质检模型分类',
                        visible: false
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'modeltypename',
                        sortable: true,
                        title: '质检模型分类'
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'poststatus',
                        title: '状态',
                        sortable: true,
                        width: 60,
                        formatter: function (value, row, index) {
                            var str = "";
                            var color = "#000";
                            if (value == "1") {
                                color = "stateGreen";
                            }
                            str = bs.changeState(value, tools.stateArr);
                            return "<span class='" + color + "'>" + str + "</span>";
                        }
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'testtimes',
                        title: '测检状态',
                        sortable: true,
                        width: 60,
                        formatter: function (value, row, index) {
                            var str = "";
                            var color = "#000";
                            if (value == "1") {
                                color = "stateGreen";
                            }
                            str = bs.changeState(value, tools.testStateArr);
                            return "<span class='" + color + "'>" + str + "</span>";
                        }
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'username',
                        sortable: true,
                        title: '创建人'
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'createtime',
                        title: '创建时间',
                        sortable: true,
                        formatter: function (value, row, index) {
                            return dateFormatUtil(value);
                        }
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'onsettime',
                        title: '上线时间',
                        sortable: true,
                        formatter: function (value, row, index) {
                            return dateFormatUtil(value);
                        }
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'lastupdatetime',
                        title: '最后更新时间',
                        sortable: true,
                        formatter: function (value, row, index) {
                            return dateFormatUtil(value);
                        }

                    }, {
                        align: "center",
                        halign: "center",
                        field: 'note',
                        title: '备注',
                        formatter: function (value, row, index) {
                            if (value == null) {
                                value = ""
                            }
                            return "<div class='noteBoxTable' title='" + value + "'>" + value + "</div>";
                        }
                    }
                ],
                onLoadSuccess: function (data) {  //加载成功时执行
                    resize.me();
                    if (!data || !data.total || data.total == 0) {
                        var src = basePath + "/assert/image/nodata.png";
                        $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                    }
                },
                onLoadError: function () {  //加载失败时执行
                    var src = basePath + "/assert/image/nodata.png";
                    $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                },
                formatLoadingMessage: function () {
                    return '<div class="loaded">' +
                        '<div class="loader">' +
                        '<div class="loader-inner line-scale-pulse-out">' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '<div>请稍等，数据正在加载中...</div>';
                },
                onExpandRow: function (index, row, $detail) {
                    //这一步就是相当于在当前点击列下新创建一个table
                    InitSubTable2(index, row, $detail);
                },
            });
        };
        //初始化子表格(无线循环)
        InitSubTable2 = function (index, row, $detail) {
            var parentid = row.id;
            var cur_table = $detail.html('<table></table>').find('table');
            $(cur_table).bootstrapTable({
                data: row.modelrulelist,
                queryParams: {strParentID: parentid},
                ajaxOptions: {strParentID: parentid},
                clickToSelect: true,
                uniqueId: "id",
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    {
                        title: '序号',//标题  可不加
                        field: 'id',
                        width: 60,
                        formatter: function (value, row, index) {
                            return index + 1
                        }
                    },
                    {
                        field: 'ruletypename',
                        title: '规则分类名称',
                    },
                    {
                        field: 'rulename',
                        width: 150,
                        title: '规则名称',
                        formatter: function (value, row, index) {
                            return '<a href="javascript:;" class="commonDetail" data-type="rule" title="查看规则信息">'+value+'</a>';
                        },
                        events: {
                            'click .commonDetail': function (e, value, row, index) {
                                var type=$(this).attr("data-type");
                                var param={};
                                param.idcombinationRule=row.ruleid;
                                modelRule.init($("body"),type,param);
                            }
                        }
                    },
                    {
                        field: 'userfor',
                        title: '规则属性',
                        formatter: function (value, row, index) {
                            var str = "";
                            if (value == "0") {
                                str = "系统"
                            } else if (value == "1") {
                                str = "人工"
                            }
                            return str;
                        }
                    },
                    {
                        field: 'fateful',
                        title: '致命性',
                        formatter: function (value, row, index) {
                            var str = "";
                            if (value == "0") {
                                str = "否"
                            } else {
                                str = "是"
                            }
                            if(row.signscore == 1) {
                                return ''
                            }else{
                                return str;
                            }
                        }
                    }, {
                        field: 'scorepertime',
                        title: '单次分值',
                        formatter: function (value, row, index) {
                          if(row.fateful == 1){
                              return '--'
                          }else{
                              if(value === 0){
                                  if(row.signscore != 1){
                                    value = '-'+ value
                                  }
                              }
                              return value
                          }
                        }
                    }, {
                        field: 'maxscore',
                        title: '分值上限'
                    }
                ],
                onLoadSuccess: function (data) {  //加载成功时执行
                    if (!data.total || data.total == 0) {
                        var src = basePath + "/assert/image/nodata.png";
                        $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                    }
                },
                onLoadError: function () {  //加载失败时执行
                    var src = basePath + "/assert/image/nodata.png";
                    $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                },
                formatLoadingMessage: function () {
                    return '<div class="loaded">' +
                        '<div class="loader">' +
                        '<div class="loader-inner line-scale-pulse-out">' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '<div>请稍等，数据正在加载中...</div>';
                }
            });
        };
        return oTableInit;
    };
    //    已选规则表格
    var TableInit1 = function ($elem) {
        var oTableInit1 = new Object();
        //初始化Table
        oTableInit1.Init = function ($elem, jsonData) {
            $elem.bootstrapTable('destroy');
            $elem.bootstrapTable({
                data: jsonData,
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                sortable: true,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                pagination: false, // 是否显示分页（*）
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 5,                       //每页的记录行数（*）
                pageList: [5],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                contentType: "application/x-www-form-urlencoded",
                strictSearch: true,
                showColumns: false,                  //是否显示所有的列
                showRefresh: false,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: false,                //是否启用点击选中行
                uniqueId: "no",                     //每一行的唯一标识，一般为主键列
                showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,
                cellStyle: {
                    css: {"background-color": "#fff"}
                },//是否显示父子表
                columns: [
                    {
                        title: '序号',//标题  可不加
                        field: 'id',
                        width: 60,
                        formatter: function (value, row, index) {
                            return index + 1
                        }
                    },
                    {
                        field: 'ruleid',
                        title: '规则id',
                        visible: false
                    },
                    {
                        field: 'ruletypename',
                        title: '规则分类名称',
                    },
                    {
                        field: 'rulename',
                        width: 150,
                        title: '规则名称'
                    },
                    {
                        field: 'userfor',
                        title: '规则属性',
                        formatter: function (value, row, index) {
                            var str = "";
                            if (value == "0") {
                                str = "系统"
                            } else if (value == "1") {
                                str = "人工"
                            }
                            return str;
                        }
                    },
                    {
                        field: 'fateful',
                        title: '致命性',
//                        width: 150,
                        formatter: function (value, row, index) {
                            var ckStr1 = value == "0" ? "checked" : "";
                            var ckStr2 = value == "0" ? "" : "checked";
                            var sign_default_score = row.signscore;
                            var html = "";
                            if ( sign_default_score == -1) {//如果是减分才有致命性 加分没有致命性概念
                                html = '<div><div id="radio_box">' +
                                    '<input type="radio"  value="1" name="fateful' + index + '" ' + ckStr2 + ' data-id="' + row.id + '">是' +
                                    '<input type="radio"  value="0" name="fateful' + index + '" ' + ckStr1 + ' data-id="' + row.id + '">否' +
                                    '</div></div>'
                            }
                            return html;
                        }
                    }, {
                        field: 'scorepertime',
                        title: '单次分值',
                        formatter: function (value, row, index) {
                            if(value == null){
                                value=""
                            }
                            if (!isNaN(value) && value.length!=0){
                                value = Math.abs(value);
                            }
                            var sign_default_score = row.signscore;
                            var char = "-";
                            if (sign_default_score == 1) {
                                char = "+"
                            }
                            var html = '<span style="position:relative;left:13px;top:-2px; display: inline-block;width: 6px;">' + char + '</span><input  class="oneNum oneNum' + row.id + '" type="text" style="width:50px;text-align: center;padding-left: 13px;" value="' + value + '" autocomplete="off" data-id="' + row.id + '"/>';
                            if (row.fateful == "1") {
                                html = '<span style="position:relative;left:13px;top:-2px; display: inline-block;width: 6px;">' + char + '</span><input  class="oneNum oneNum' + row.id + '" type="text" style="width:50px;text-align: center;padding-left: 13px;" value="' + value + '" disabled autocomplete="off" data-id="' + row.id + '"/>'
                            }
                            return html;
                        }
                    }, {
                        field: 'maxscore',
                        title: '分值上限',
                        formatter: function (value, row, index) {
                            if(value == null){
                                value=""
                            }
                            var sign_default_score = row.signscore;
                            var char = "-";
                            if (sign_default_score == 1) {
                                char = "+"
                            }
                            if (value < 0) {
                                value = Math.abs(value);
                            }
                            return '<span style="position:relative;left:13px;top:-2px; display: inline-block;width: 6px;">' + char + '</span><input  class="maxNum maxNum' + row.id + '" type="text" style="width:50px;text-align: center;padding-left: 13px;" value="' + value + '" autocomplete="off" data-id="' + row.id + '"/>'
                        }
                    }, {
                        field: 'Button',
                        title: '操作',
                        formatter: function (value, row, index) {
                            return [
                                '<a href="javascript:;" class="fa fa-trash handleBtn del" title="删除" data-id="' + row.ruleid + '"></a>'
                            ]
                        }
                    }
                ],
                onPostBody: function (data) {
                    $(".rule_box .fixed-table-body").css("maxHeight", "390px");
                    var reg = /^[0-9]\d*$/;
                    $("body .oneNum").unbind("keyup").on("keyup", function () {
                        var val = $(this).val();
                        var maxElem = $(this).parents("td").next().find(".maxNum");
                        if (!reg.test(val)) {
                            $(this).val("")
                        } else {
                            $(this).val(parseInt($(this).val() + ""));
                            maxElem.blur();
                        }
                    });
                    $("body .oneNum").unbind("blur").on("blur", function () {
                        var val = $(this).val();
                        var id = $(this).attr("data-id");
                        for (var i = 0; i < jsonData.length; i++) {
                            var idO = jsonData[i].id;
                            if (id == idO) {
                                if (jsonData[i].signscore!=1) {//判断该字段没有 或者为负数时 是减分 否则加分
                                    if((val+"").length!=0){
                                        jsonData[i].scorepertime = -val;
                                    }else{
                                        jsonData[i].scorepertime = val;
                                    }
                                }else{
                                    jsonData[i].scorepertime = val;
                                }
                            }
                        }
                    });
                    $("body .maxNum").unbind("keyup").on("keyup", function () {
                        var val = $(this).val();
                        if (!reg.test(val)) {
                            $(this).val("")
                        } else {
                            $(this).val(parseInt($(this).val() + ""))
                        }
                    });
                    $("body .maxNum").unbind("blur").on("blur", function () {
                        var val = $(this).val();
                        var id = $(this).attr("data-id");
                        for (var i = 0; i < jsonData.length; i++) {
                            var idO = jsonData[i].id;
                            if (id == idO) {
                                if (jsonData[i].signscore!=1) {//判断该字段没有 或者为负数时 是减分 否则加分
                                    if((val+"").length!=0){
                                        jsonData[i].maxscore = -val;
                                    }else{
                                        jsonData[i].maxscore = val;
                                    }
                                }else{
                                    jsonData[i].maxscore = val;
                                }
                            }
                        }
                    });
                    $elem.find("input[type='radio']").unbind("click").on("click", function () {
                        var val = $(this).val();
                        var maxElem = $(this).parents("td").next().next().find(".maxNum");
                        var oneElem = $(this).parents("td").next().find(".oneNum");
                        if (val == "1") {//若果是非致命性
                            oneElem.attr("disabled", true);
                            validateFun.initValidatorScore($elem.parents("form").eq(0), '.' + maxElem.attr("class").split(" ")[1], false);
                            var inputTop = maxElem.offset().top;
                            $(".jqx-validator-hint").each(function () {
                                var top = parseFloat($(this).css("top"));
                                if (top == inputTop) {
                                    $(this).remove();
                                }
                            })
                        } else {//若果是致命性
                            oneElem.attr("disabled", false);
                            validateFun.initValidatorScore($elem.parents("form").eq(0), '.' + maxElem.attr("class").split(" ")[1], true);
                            maxElem.blur();
                        }
                        var id = $(this).attr("data-id");
                        for (var i = 0; i < jsonData.length; i++) {
                            var idO = jsonData[i].id;
                            if (id == idO) {
                                jsonData[i].fateful = val;
                            }
                        }
                    });
                    try {
                        if (jsonData.length != 0) {
                            validate();
                        }
                    } catch (e) {

                    }
                },
                onLoadSuccess: function (data) {  //加载成功时执行
                    if (!data.total || data.total == 0) {
                        var src = basePath + "/assert/image/nodata.png";
                        $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                    }
                },
                onLoadError: function () {  //加载失败时执行
                    var src = basePath + "/assert/image/nodata.png";
                    $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                },
                formatLoadingMessage: function () {
                    return '<div class="loaded">' +
                        '<div class="loader">' +
                        '<div class="loader-inner line-scale-pulse-out">' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '<div>请稍等，数据正在加载中...</div>';
                }
            });

        };
        validate = function () {
            $elem.find("[class^=oneNum]").each(function () {
                var $this = $(this);
//                validateFun.initValidatorOneScore($elem.parents("form").eq(0),'.' + $this.attr("class").split(" ")[1]);
                validateFun.initValidatorScore($elem.parents("form").eq(0), '.' + $this.attr("class").split(" ")[1]);
            });
            $elem.find("[class^=maxNum]").each(function () {
                var $this = $(this);
                if (!$this.parents("td").prev().find(".oneNum").attr("disabled")) {
                    validateFun.initValidatorScore($elem.parents("form").eq(0), '.' + $this.attr("class").split(" ")[1], true);
                } else {
                    validateFun.initValidatorScore($elem.parents("form").eq(0), '.' + $this.attr("class").split(" ")[1], false);
                }
            });
        };
        return oTableInit1;
    };
    //    选择规则的表格
    var TableInit2 = function () {
        var oTableInit = new Object();
        var url = tools.ruleUrl + "/combinationRule/queryCombinationRule";
        //初始化Table
        oTableInit.Init = function () {
            $('#tableRule').bootstrapTable('destroy');
            $('#tableRule').bootstrapTable({
                url: url,         //请求后台的URL（*）
                method: 'post',                      //请求方式（*）
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                sortable: true,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                height:480,
                responseHandler: function (res) {
                    tools.tableData = res.data.rows;
                    var arr = res.data.rows;
                    // 匹配已经选择的规则 让其默认选中
                    if (tools.ruleTableData.length > 0 && arr.length > 0) {
                        for (var i = 0; i < arr.length; i++) {
                            for (var j = 0; j < tools.ruleTableData.length; j++) {
                                if (tools.ruleTableData[j]["ruleid"] == arr[i]["idcombinationrule"]) {
                                    arr[i]["state"] = true;
                                }
                            }
                        }
                    }
                    if (!res.data) {
                        return {
                            "total": 0,//总页数
                            "rows": []   //数据
                        };
                    } else {
                        return {
                            "total": res.data.total,//总页数
                            "rows": arr   //数据
                        };
                    }

                },
                pagination: true, // 是否显示分页（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                contentType: "application/x-www-form-urlencoded",
                strictSearch: true,
                showColumns: false,                  //是否显示所有的列
                showRefresh: false,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                uniqueId: "no",                     //每一行的唯一标识，一般为主键列
                showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: true,
                cellStyle: {
                    css: {"background-color": "#fff"}
                },//是否显示父子表
                queryParams: function (params) {
                    var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        // rows: params.limit,//页面大小
                        // page: (params.offset / params.limit) + 1//页码
                        pageSize: params.limit,   //页面大小
                        pageNum: params.offset / params.limit + 1,  //偏移量
                        idservice: $("#classifyRule").attr("data-id"), //分类
                        rulename: $.trim($("#rulename").val()), //名称
                        author: $.trim($("#personRule").val()), //创建人
                        ruleattributes: $("#ruleattributes").val(),//规则属性
                        status: $("#stateRule").val(),//状态
                        create_time: $("#startRule").val(),//创建开始日期
                        create_time_end: $("#endRule").val(), //创建结束日期
                        publish_time: $("#startS").val(), //上线开始日期
                        publish_time_end: $("#endS").val(), //上线结束日期
                        end_time: $("#startUp").val(), //更新开始日期
                        end_time_end: $("#endUp").val(), //更新结束日期
                        sign_default_score:$("#scoreFlag").val()
//                        fatal: $("#rulefatal").val()
                    };
                    return temp;
                },
                columns: [
                    {
                        checkbox: true, // 显示一个勾选框
                        align: 'center',// 居中显示,
                        formatter: function (value, row, index) {
                            if (row.status == "0")
                                return {
                                    disabled: true//设置是否可用
                                };
                            if (row.state == true)
                                return {
                                    disabled: false,//设置是否可用
                                    checked: true//设置选中
                                };
                        }
                    },
                    {
                        align: "center",
                        halign: "center",
                        title: '序号',//标题  可不加
                        width: 60,
                        field: 'number',
                        formatter: function (value, row, index) {
                            var getOptions = $("#tableRule").bootstrapTable('getOptions');
                            var pagenum = getOptions.pageNumber;
                            var pagesize = getOptions.pageSize;
                            var st = (pagenum - 1) * pagesize;
                            return (st + index + 1) + "";
                        }
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'rulename',
                        title: '规则名称'
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'ruleattributes',
                        title: '规则属性',
                        formatter: function (value, row, index) {
                            return bs.changeState(value, tools.ruleattributesArr);
                        }
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'ruleclassify',
                        title: '规则分类'
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'author',
                        title: '创建人',
//                        visible: false
                    },

                    {
                        align: "center",
                        halign: "center",
                        field: 'status',
                        title: '发布状态',
                        width: 60,
                        formatter: function (value, row, index) {
                            var str = "";
                            var color = "#000";
                            if (value == "1") {
                                color = "stateGreen";
                            }
                            str = bs.changeState(value, tools.stateArr);
                            return "<span class='" + color + "'>" + str + "</span>";
                        }
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'publish_time',
                        title: '上线时间'
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'end_time',
                        title: '更新时间'

                    }, {
                        align: "center",
                        halign: "center",
                        field: 'fatal',
                        title: '致命性',
                        formatter: function (value, row, index) {
                            if(row.sign_default_score == 1) {
                                return ''
                            }else{
                                return bs.changeState(value, tools.fatalArr);
                            }
                        }
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'default_score',
                        title: '建议分值',
                        formatter: function (value, row, index) {
                            if(value!=null){
                                if(row.sign_default_score==-1){
                                    value="-"+value;
                                }
                            }
                            return value;
                        }
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'notes',
                        title: '备注'
                    }
                ],

                onLoadSuccess: function (data) {  //加载成功时执行
                    resize.me();
                    if (!data.total || data.total == 0) {
                        var src = basePath + "/assert/image/nodata.png";
                        $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                    }
                },
                onLoadError: function () {  //加载失败时执行
                    var src = basePath + "/assert/image/nodata.png";
                    $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                },
                formatLoadingMessage: function () {
                    return '<div class="loaded">' +
                        '<div class="loader">' +
                        '<div class="loader-inner line-scale-pulse-out">' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '<div>请稍等，数据正在加载中...</div>';
                },
                onCheck: function (row, tr) {
                    tools.ruleTableData.push(rule.addNewRule(row));
                },
                onUncheck: function (row, tr) {
                    var id = row.idcombinationrule;
                    for (var i = 0; i < tools.ruleTableData.length; i++) {
                        if (tools.ruleTableData[i].ruleid == id) {
                            tools.ruleTableData.splice(i, 1)
                        }
                    }
                },
               onCheckAll: function (row, tr) {
                   var arr= $("#tableRule").bootstrapTable("getSelections");
                   for(var j=0;j<arr.length;j++){
                       var code=false;
                       for (var i = 0; i < tools.ruleTableData.length; i++) {
                           if (tools.ruleTableData[i].ruleid == arr[j].idcombinationrule) {
                               code=true;
                           }
                       }
                       if(!code){//如果已选规则不包含 该规则 则追到数组里
                           tools.ruleTableData.push(rule.addNewRule(arr[j]));
                       }
                   }
               },
               onUncheckAll: function (row, tr) {
                   var arr = $("#tableRule").bootstrapTable("getData");
                   for(var j=0;j<arr.length;j++){
                       for (var i = 0; i < tools.ruleTableData.length; i++) {
                           if (tools.ruleTableData[i].ruleid == arr[j].idcombinationrule) {
                               tools.ruleTableData.splice(i, 1)
                           }
                       }
                   }
               },
                onExpandRow: function (index, row, $detail) {
                    //这一步就是相当于在当前点击列下新创建一个table
                    $.ajax({
                        url: tools.ruleUrl + "/combinationRule/getcombinationRulebyid",
                        type: "post",
                        data: {
                            "idcombinationRule": row.idcombinationrule
                        },
                        async: false,
                        success: function (result) {
                            var code = result.code;
                            var data = result.data;
                            if (code) {
                                if (data) {
                                    var textId = data.text;
                                    var volumeId = data.volume;
                                    var voiceSpeedId = data.voicespeed;
                                    var grabId = data.grab;//强插话
                                    var channelsId = data.channels;
                                    var muteId = data.mute;
                                    var negativeId = data.negative;
                                    var arr = [];
                                    var ruleobj;
                                    if (textId) {
                                        var textIdArr = textId.split(",");
                                        $.each(textIdArr, function (index, value) {
                                            ruleobj = menuRule.getRuleOne("文本", value);
                                            if (ruleobj) {
                                                arr.push(ruleobj);
                                            }
                                        });
                                    }
                                    if (volumeId) {
                                        var volumeIdArr = volumeId.split(",");
                                        $.each(volumeIdArr, function (index, value) {
                                            ruleobj = menuRule.getRuleOne("音量", value);
                                            if (ruleobj) {
                                                arr.push(ruleobj);
                                            }
                                        });
                                    }
                                    if (voiceSpeedId) {
                                        var voiceSpeedIdArr = voiceSpeedId.split(",");
                                        $.each(voiceSpeedIdArr, function (index, value) {
                                            ruleobj = menuRule.getRuleOne("语速", value);
                                            if (ruleobj) {
                                                arr.push(ruleobj);
                                            }
                                        });
                                    }
                                    if (grabId) {
                                        var grabIdArr = grabId.split(",");
                                        $.each(grabIdArr, function (index, value) {
                                            ruleobj = menuRule.getRuleOne("抢插话", value);
                                            if (ruleobj) {
                                                arr.push(ruleobj);
                                            }
                                        });
                                    }
                                    if (channelsId) {
                                        var channelsIdArr = channelsId.split(",");
                                        $.each(channelsIdArr, function (index, value) {
                                            ruleobj = menuRule.getRuleOne("声道", value);
                                            if (ruleobj) {
                                                arr.push(ruleobj);
                                            }
                                        });

                                    }
                                    if (muteId) {
                                        var muteIdArr = muteId.split(",");
                                        $.each(muteIdArr, function (index, value) {
                                            ruleobj = menuRule.getRuleOne("静音", value);
                                            if (ruleobj) {
                                                arr.push(ruleobj);
                                            }
                                        });
                                    }
                                    if (negativeId) {
                                        var negativeIdArr = negativeId.split(",");
                                        $.each(negativeIdArr, function (index, value) {
                                            ruleobj = menuRule.getRuleOne("负面情绪", value);
                                            if (ruleobj) {
                                                arr.push(ruleobj);
                                            }
                                        });
                                    }
                                    row.arr = arr.sort(bs.sortBy("number"));
                                }
                                InitSubTable3(index, row, $detail);
                            }
                        }
                    });

                },
            });
        };
        //初始化子表格(无线循环)
        InitSubTable3 = function (index, row, $detail) {
            var parentid = row.idcombinationrule;
            var cur_table = $detail.html('<table></table>').find('table');
            $(cur_table).bootstrapTable({
                data: row.arr,
                queryParams: {strParentID: parentid},
                ajaxOptions: {strParentID: parentid},
                clickToSelect: true,
                uniqueId: "id",
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    {
                        title: '序号',//标题  可不加
                        field: 'number',
                        width: 60
                    },
                    {
                        field: 'type',
                        title: '类型',
                        width: 100
                    },
                    {
                        field: 'content',
//                    width: 300,
                        title: '内容',
                        formatter: function (value, row, index) {
                            var timesStr = "";
                            var voiceSpeedStr = "";
                            var channel = "";
                            var contentStr = "";
                            var durationStr = "";
                            var hitStr = "";
                            if (row.voiceSpeedStr) {
                                voiceSpeedStr = row.voiceSpeedStr;
                            }
                            if (row.timesStr) {
                                timesStr = row.timesStr;
                            }
                            if (row.channel) {
                                channel = row.channel;
                            }
                            if (row.contentStr) {
                                contentStr = row.contentStr;
                            }
                            if (row.durationStr) {
                                durationStr = row.durationStr;
                            }
                            if (row.hit!=null) {
                                var hit = row.hit;
                                if (hit == "0") {
                                    hitStr = "否"
                                } else if (hit == "1") {
                                    hitStr = "是"
                                }
                            }

                            var conHtml = "";
                            if (voiceSpeedStr) {
                                conHtml += voiceSpeedStr + "</br>";
                            }
                            if (timesStr) {
                                conHtml += timesStr + "</br>";
                            }
                            if (channel) {
                                conHtml += channel + "</br>";
                            }
                            if (contentStr) {
                                conHtml += contentStr + "</br>";
                            }
                            if (durationStr) {
                                conHtml += durationStr + "</br>";
                            }
                            if (hitStr) {
                                conHtml += "命中：" + hitStr + "</br>";
                            }
                            return conHtml;
                        }
                    },
                    {
                        field: 'position',
                        title: '位置'
                    }
                ],
                onLoadSuccess: function (data) {  //加载成功时执行
                    if (!data.total || data.total == 0) {
                        var src = basePath + "/assert/image/nodata.png";
                        $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                    }
                },
                onLoadError: function () {  //加载失败时执行
                    var src = basePath + "/assert/image/nodata.png";
                    $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                },
                formatLoadingMessage: function () {
                    return '<div class="loaded">' +
                        '<div class="loader">' +
                        '<div class="loader-inner line-scale-pulse-out">' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '<div>请稍等，数据正在加载中...</div>';
                }
            });
        };
        return oTableInit;
    };
    var menu = {
        init: function () {
            menu.render($("#jstree"));
        },
        render: function (elem) {
            var jstree = elem;
            jstree.jstree("destroy");
            jstree.data('jstree', false).empty();
            jstree.jstree({
                "core": {
                    "animation": false,
                    "multiple": false,
                    "check_callback": true,
                    'data': function (obj, callback) {
                        $.ajax({
                            type: "GET",
                            url: basePath + 'rest/model/select/modelTypeTree',
                            dataType: "json",
//                            async: false,
                            success: function (data) {
                                var result = data.data;
                                if (!result.id) {
                                    $("#addType").show();
                                    $("#addType").prev().prev().width(144);
                                }
                                if (result != null) {
                                    var arr = [];
                                    arr.push(result);
                                    callback.call(this, menu.loopMenu(arr));
                                }
                                menu.changeMenu(elem);
                                menu.search(elem);
                            }
                        });
                    }
                },
                "types": {
                    "default": {
                        "icon": "jstree-folder"
                    },
                    "html": {
                        "icon": "jstree-file"
                    }
                },
                "plugins": ["types", "search", "unique", "contextmenu"],
                'contextmenu': {
                    'items': menu.customMenu     //每个节点都会调用这个函数
                }
            }).bind('loaded.jstree', function (e, data) {
                jstree.jstree("deselect_all", true);
                $("li[aria-selected='true']").click();
            }).bind("delete_node.jstree", function (event, data) {
                menu.delMenu(event, data);
            });
        },
        renderO: function (elem) {
            var jstree = elem;
            jstree.jstree("destroy");
            jstree.data('jstree', false).empty();
            jstree.jstree({
                "core": {
                    "animation": false,
                    "multiple": false,
                    "check_callback": true,
                    'data': function (obj, callback) {
                        $.ajax({
                            type: "GET",
                            url: basePath + 'rest/model/select/modelTypeTree',
                            dataType: "json",
//                            async: false,
                            success: function (data) {
                                var result = data.data;
                                if (result != null) {
                                    var arr = [];
                                    arr.push(result);
                                    callback.call(this, menu.loopMenu(arr));
                                }
                                menu.changeMenu(elem);
                                menu.search(elem);
                            }
                        });
                    }
                },
                "types": {
                    "default": {
                        "icon": "jstree-folder"
                    },
                    "html": {
                        "icon": "jstree-file"
                    }
                },
                "plugins": ["types", "search", "unique"],
            }).bind('loaded.jstree', function (e, data) {
                jstree.jstree("deselect_all", true);
                $("li[aria-selected='true']").click();
            });
        },
        delMenu: function (event, data) {
            var id = data.node.id;
            var params = {"ids": parseInt(id)};
            $.ajax({
                type: "GET",
                url: basePath + 'rest/model/delete/modelTypeByExample',
                dataType: "json",
                data: params,
                success: function (result) {
                    var msg = result.msg;
                    if (result.code != 0) {
                        toastrCog.error(msg, 3000)
                    } else {
                        menu.refresh();
                        toastrCog.success(msg, 1000)
                    }
                }
            });

        },
        customMenu: function (node) {
            var items = {
                'add': {
                    'label': '新增分类',
                    'action': function (data) {
                        var inst = $.jstree.reference(data.reference),
                            obj = inst.get_node(data.reference);
                        if (obj.id == -9999) {
                            // 如果某个节点id为-9999 不允许在该节点新增
                            toastrCog.error("不能选择该节点进行添加", 3000);
                            return false;
                        }
                        var provinceid = "", parentid = "", provincecode;
                        if (obj.parents.length == 2) {
                            provinceid = Math.abs(obj.id);
                            provincecode = tools.getCodeInId(provinceid);
                            $("#typeParentModal").prop("disabled", false);
                            $("#typeParentModal").parents(".form-group").hide();
                        } else if (obj.parents.length > 2) {
                            provinceid = Math.abs(obj.parents[obj.parents.length - 3]);
                            provincecode = tools.getCodeInId(provinceid);
                            parentid = Math.abs(obj.id);
                            $("#typeParentModal").prop("disabled", true);
                            $("#typeParentModal").parents(".form-group").show();
                        }
                        $("#addTypeForm")[0].reset();
                        $("#addTypeModal").modal("show");
                        $("#addTypeModal").attr("data-code", "add");
                        $("#addTypeForm").find(".modal-title").html("添加分类");
                        $("#addTypeModal").attr("data-id", parentid);

                        $("#proTypeModal").prop("disabled", true);
                        tools.updataSelect($("#proTypeModal"), provincecode);
                        $("#proTypeModalAddInput").val(provincecode);

                        tools.selectType(provincecode, $("#typeParentModal"), "");
                        tools.updataSelect($("#typeParentModal"), parentid);
                        $("#typeParentModalAddInput").val(parentid);
                    }
                },
                'addModel': {
                    'label': '添加模型',
                    'action': function (data) {
                        $("#btnAdd").click();
                    }
                },
                'edit': {
                    'label': '编辑',
                    'action': function (data) {
                        var inst = $.jstree.reference(data.reference),
                            obj = inst.get_node(data.reference);
                        if (obj.id < 0) {
                            // 如果某个节点id为-9999 不允许在该节点新增
                            toastrCog.error("不能选择该节点进行编辑", 3000);
                            return false;
                        }
                        $("#addTypeModal").modal("show");
                        $("#addTypeModal").attr("data-code", "edit");
                        $("#addTypeForm").find(".modal-title").html("编辑分类");
                        var provinceid = "", parentid = "", provincecode;
                        if (obj.parents.length == 2) {
                            provinceid = Math.abs(obj.id);
                            provincecode = tools.getCodeInId(provinceid);
                            $("#typeParentModal").prop("disabled", false);
                        } else if (obj.parents.length > 2) {
                            provinceid = Math.abs(obj.parents[obj.parents.length - 3]);
                            provincecode = tools.getCodeInId(provinceid);
                            parentid = Math.abs(obj.parents[0]);
                            $("#typeParentModal").prop("disabled", true);
                        }
                        $("#addTypeModal").attr("data-id", Math.abs(obj.id));
                        if (obj.parents.length >= 2 && obj.parents.length <= 3) {
                            $("#typeParentModal").parents(".form-group").hide();
                        } else if (obj.parents.length > 3) {
                            $("#typeParentModal").parents(".form-group").show();
                        }
                        $("#proTypeModal").prop("disabled", true);
                        tools.updataSelect($("#proTypeModal"), provincecode);
                        $("#proTypeModalAddInput").val(provincecode);
                        tools.selectType(provincecode, $("#typeParentModal"), $("#addTypeModal").attr("data-id"));
                        tools.updataSelect($("#typeParentModal"), parentid);
                        $("#typeParentModalAddInput").val(parentid);
                        $("#modelTypeName").val(obj.text);
                        $("#remarkTypeAdd").val(obj.original.note);
                    }
                },
                'delete': {
                    'label': '删除',
                    'action': function (data) {
                        var inst = $.jstree.reference(data.reference),
                            obj = inst.get_node(data.reference);
                        if (obj.id == -9999) {
                            // 如果某个节点id为-9999 不允许在该节点新增
                            toastrCog.error("不能删除改节点", 3000);
                            return false;
                        }
                        $.ajax({
                            type: "GET",
                            url: basePath + 'rest/model/checkDelete/modelTypeByExample',
                            dataType: "json",
                            data: {
                                ids: obj.id
                            },
                            success: function (result) {
                                var msg = result.msg;
                                if (result.code == 0) {
                                    $("#delText").html("");
                                    $("#delModalCon").modal("show");
                                } else if (result.code == 1) {
                                    $("#delText").html(msg);
                                    $("#delModalCon").modal("show");
                                } else if (result.code == 2) {
                                    $("#delText").html("");
                                    toastrCog.error(msg, 3000);
                                }
                            }
                        });
                        $("#delNameCon").html(obj.text).css("color", "rgb(50, 136, 226)");
                        $("#delConBtn").on("click", function () {
                            if (inst.is_selected(obj)) {
                                inst.delete_node(inst.get_selected());
                            } else {
                                inst.delete_node(obj);
                            }
                            tools.updataSelect($("#pro"), "");
                            $("#classify").val("");
                            tools.tableRefresh();
                            $("#delModalCon").modal("hide");
                        });
                    }
                },
                'addPro': {
                    'label': '新增分类',
                    'action': function (data) {
                        $("#addType").click();
                    }
                }

            };

            var code = menu.checkData(node.id);
            if (node.id < 0 && node.id != "-9999") {
                delete items.edit;  //如果是省份 删除编辑方法
            }
            if (code == 1) { //如果 有数据  删除编辑方法
                delete items.addModel;  //如果是省份 删除新增模型方法
            }
            if (code == 2) { //如果 有数据  删除编辑方法
                delete items.add;  //如果是省份 删除新增模型方法
            }
            if (node.id == "-9999") {
                delete items.add;  //如果是省份 删除新增模型方法
                delete items.edit;  //如果是省份 删除编辑模型方法
                delete items.delete;  //如果是省份 删除 删除模型方法
                delete items.addModel;  //如果是省份 删除新增模型方法
            } else {
                delete items.addPro;  //如果是根节点 删除新增模型方法
            }
            return items;
        },
        checkData: function (id) {
            var msg = "";
            var params = {"id": id};
            $.ajax({
                type: "GET",
                url: basePath + 'rest/model/checkData/modelTypeByExample',
                dataType: "json",
                data: params,
                async: false,
                success: function (result) {
                    msg = result.code;
                }
            });
            return msg;
        },
        rootLoopMenu: function (array, obj) {
            if (array.length > 0) {
                var parentid = obj.parentid;
                for (var i = 0; i < array.length; i++) {
                    var code = 0;
                    var id = array[i]["id"];
                    if (parentid == id) {
                        array[i]["children"].push(obj);
                        return array;
                    } else {
                        code++;
                    }
                    if (code == array.length) {
                        for (var j = 0; j < code; j++) {
                            menu.rootLoopMenu(array[j]["children"], obj);
                        }
                    }
                }
                return array;
            }
        },
        loopMenu: function (array) {
            if (array && array.length > 0) {
                for (var i = 0; i < array.length; i++) {
                    var children = array[i]["children"];
                    if (children.length <= 0) {
                        array[i].type = "html"
                    } else {
//                        if(i<=1){
                        array[i].state = {"opened": "true"}
//                        }
                    }
                    if (children) {
                        menu.loopMenu(children);
                    }
                }
                return array;
            } else {
                return []
            }
        },
        changeMenu: function (elem) {
            elem.unbind("changed.jstree").on("changed.jstree", function (e, data) {
                var val = data.selected;
                var selectNode = elem.jstree("get_node", data.selected);
                if (val.length > 0) {
                    if (elem.attr("id") == "jstree") {
                        if (val != -9999) {
                            if (val < 0) {
                                tools.updataSelect($("#pro"), tools.getCodeInId(Math.abs(val)));
                                $("#classify").val("");
                            } else {
                                var parents = data.node.parents;
                                $("#classify").val(data.selected);
                                tools.updataSelect($("#pro"), tools.getCodeInId(Math.abs(parents[parents.length - 3])));
                            }
                        } else {
                            tools.updataSelect($("#pro"), "");
                            $("#classify").val("");
                        }
                        tools.tableRefresh();
                    } else if (elem.attr("id") == "jsTreeCopy") {
                        if (selectNode) {
                            $("#copyModal").attr("data-idservice", selectNode.original.id);
                            if (selectNode.original.parentid != 1 && selectNode.children.length == 0) {
                                $(".ceng").hide();
                                $(".ceng").next().show();
                            } else {
                                $(".ceng").show();
                                $(".ceng").next().hide();
                            }
                        }
                    }
                }
            });
        },
        search: function (elem) {
            elem.prev().find(".fa-search").on("click", function () {
                elem.jstree(true).search($.trim(elem.prev().find("input").val()));
                menu.scrollSearch(elem);
            });
            elem.prev().find("input").on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    elem.jstree(true).search($.trim(elem.prev().find("input").val()));
                    menu.scrollSearch(elem);
                }
            })
        },
        scrollSearch: function (elem) {
            if (elem.find(".jstree-search").length > 0) {
                var odiv = elem.find(".jstree-search").eq(0)[0];
                var top = odiv.offsetTop;
                var height = odiv.offsetHeight;
                var elemTop = elem[0].scrollTop;
                //获取当前屏幕大小
                var size = elem.height();
                //加上元素本身的高度，是元素全部出现事件
                if ((top + height) < (elemTop + size) && (top + height) > elemTop) {

                } else {
                    elem.animate({scrollTop: top - 70}, "slow");
                }
            }
        },
        getMenuData: function () {
            var arr = [];
            $.ajax({
                type: "GET",
                url: basePath + 'rest/model/select/modelTypeTree',
                async: false,
                success: function (result) {
                    if (result.data != null) {
                        arr.push(result.data);
                    }
                }
            });
            return arr;
        },
        refresh: function () {
            var tree = $('#jstree');
//            tree.jstree(true).settings.core.data = menu.loopMenu(menu.getMenuData()); // 新数据
            tree.jstree(true).refresh(); //刷新树
        },
    };
    var menuRule = {
        init: function () {
            menuRule.render($("#jstreeRule"));
        },
        render: function (elem) {
            var jstree = elem;
            jstree.jstree("destroy");
            jstree.data('jstree', false).empty();
            jstree.jstree({
                "core": {
                    "animation": false,
                    "multiple": false,
                    "check_callback": true,
                    'data': function (obj, callback) {
                        $.ajax({
                            type: "POST",
                            url: tools.ruleUrl + '/service/listservicebyidparent',
//                            dataType: "json",
                            data: {
                                idparent: $("#idservice").val()
                            },
                            success: function (data) {
                                var result = data.data;
                                if (result != null) {
                                    var arr = [];
                                    for (var i = 0; i < result.length; i++) {
                                        var obj = {};
                                        var id = result[i].idservice;
                                        var name = result[i].service;
                                        var parentid = result[i].idparent;
                                        var province = result[i].province;
                                        var notes = result[i].notes;
                                        obj.id = id;
                                        obj.text = name;
                                        obj.children = [];
                                        obj.parentid = parentid;
                                        obj.province = province;
                                        obj.notes = notes;
                                        arr.push(obj);
                                    }
                                    var arr1 = [];
                                    if ($("#idservice").val() != 1) {//如果是省份人员进来
                                        arr1 = menuRule.rootLoopMenu(arr, 1);
                                        callback.call(this, menuRule.loopMenu(arr1));
                                    } else {
                                        arr1 = menuRule.rootLoopMenu(arr);
                                        callback.call(this, menuRule.loopMenu(arr1[0].children));
                                    }
                                }
                                menuRule.changeMenu(elem);
                                menuRule.search(elem);
                            }
                        });
                    }
                },
                "types": {
                    "default": {
                        "icon": "jstree-folder"
                    },
                    "html": {
                        "icon": "jstree-file"
                    }
                },
                "plugins": ["types", "search", "unique"]
            }).bind('loaded.jstree', function (e, data) {
                jstree.jstree("deselect_all", true);
                $("li[aria-selected='true']").click();
            });
        },
        rootLoopMenu: function (data, parent) {
            var tree = [];
            var temp;
            for (var i = 0; i < data.length; i++) {
                var obj = data[i];
                if (data[i].parentid == parent) {
                    temp = menuRule.rootLoopMenu(data, data[i].id);
                    if (temp.length > 0) {
                        obj.children = temp;
                    }
                    tree.push(obj);
                }
            }
            return tree;
        },
        loopMenu: function (array) {
            if (array && array.length > 0) {
                for (var i = 0; i < array.length; i++) {
                    var children = array[i]["children"];
                    if (children.length <= 0) {
                        array[i].type = "html"
                    } else {
                        array[i].state = {"opened": "true"}
                    }
                    if (children) {
                        menuRule.loopMenu(children);
                    }
                }
                return array;
            } else {
                return []
            }
        },
        changeMenu: function (elem) {
            elem.unbind("changed.jstree").on("changed.jstree", function (e, data) {
                var selectNode = elem.jstree("get_node", data.selected);
                if (elem.attr("id") == "jstreeRule") {
                    if (selectNode) {
                        $("#classifyRule").val(selectNode.original.text).attr("data-id", selectNode.original.id);
                    }
                    var oTable2 = new TableInit2();
                    oTable2.Init();
                }
            });
        },
        search: function (elem) {
            elem.prev().find(".fa-search").on("click", function () {
                elem.jstree(true).search($.trim(elem.prev().find("input").val()));
                menuRule.scrollSearch(elem);
            });
            elem.prev().find("input").on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    elem.jstree(true).search($.trim(elem.prev().find("input").val()));
                    menuRule.scrollSearch(elem);
                }
            })
        },
        scrollSearch: function (elem) {
            if (elem.find(".jstree-search").length > 0) {
                var odiv = elem.find(".jstree-search").eq(0)[0];
                var top = odiv.offsetTop;
                var height = odiv.offsetHeight;
                var elemTop = elem[0].scrollTop;
                //获取当前屏幕大小
                var size = elem.height();
                //加上元素本身的高度，是元素全部出现事件
                if ((top + height) < (elemTop + size) && (top + height) > elemTop) {

                } else {
                    elem.animate({scrollTop: top - 70}, "slow");
                }
            }
        },
        getProTreeId: function (pro) {
            $.ajax({
                url: tools.ruleUrl + "/service/getservicebyprovince",
                type: "post",
                data: {
                    "province": pro
                },
                async: false,
                success: function (result) {
                    var code = result.code;
                    var data = result.data;
                    if (code) {
                        $("#idservice").val(data.idservice);
                        $("#classifyRule").val("").attr("data-id", $("#idservice").val());
                    }
                }
            });
        },
        getRuleOne: function (type, id) {
            var url = "";
            var params = {};
            if (type == "文本") {
                url = "/text/showchildlisttextbyid";
                params.idtext = id;
            } else if (type == "静音") {
                url = "/mute/showchildlistmutebyid";
                params.idmute = id;
            } else if (type == "音量") {
                url = "/volume/showchildlistvolumebyid";
                params.idvolume = id;
            } else if (type == "语速") {
                url = "/voiceSpeed/showchildlistvoicespeedbyid";
                params.idvoiceSpeed = id;
            } else if (type == "负面情绪") {
                url = "/negative/showchildlistnegativebyid";
                params.idnegative = id;
            } else if (type == "抢插话") {
                url = "/grab/showchildlistgrabbyid";
                params.idgrab = id;
            } else {
                url = "/channels/showchildlistchannelsbyid";
                params.idchannels = id;
            }
            var obj;
            $.ajax({
                url: tools.ruleUrl + url,
                type: "post",
                data: params,
                async: false,
                success: function (result) {
                    var code = result.code;
                    var data = result.data;
                    if (code) {
                        obj = data;
                        obj.id = id;
                    } else {
                        toastrCog.error(result.message);
                    }
                }
            });
            return obj;
        },
    };
    var resize = {
        init: function () {
            resize.me();
            $(window).resize(function () {
                resize.me();
            })
        },
        me: function () {
            var winW = $(window).width();
            var winH = $(window).height();
            $(".ibox").width(winW - 20);
            $(".ibox").height(winH - 25);
            $("#jstree").height(winH - 60);
            $(".model_right").width(winW - 240);
            bs.autoTableHeight($('#myTable'),winH -$(".tools_bar").height()-22-$(".search").height())
            $("#addRuleModel .fixed-table-body").css("maxHeight", (670 - 180 - 58) + "px");
            $(".rule_box .fixed-table-body").css("maxHeight", "390px");
        }
    };
    var tools = {
        maxTextLength: null,
        ruleUrl: "",
        tableData: [],
        ruleTableData: [],
        classifyArr: [],
        stateArr: [
            {
                name: "全部",
                value: ""
            }
        ],
        seatIdArr: [],
        seatAllArr: [],
        proArr: [],//存放省份信息
        ruleattributesArr: [],
        fatalArr: [],
        scoreFlagArr:[],
        init: function () {
            tools.getConfig();
            tools.selectInit();
            tools.tabSearch();
            tools.enterSearch();
            tools.search();
            tools.reset();
            tools.refresh();
            tools.addModel();
            tools.editModel();
            tools.changeform();
            tools.saveModel();
            tools.delModel();
            tools.startModel();
            tools.stopModel();
            tools.copyModel();
            tools.export();
            $("#addModal").on("hidden.bs.modal", function () {
                var form = $("#addModelForm");
                tools.hideLabel(form, '#proModalAddInput');
                tools.hideLabel(form, '#typeModalAddInput');
                tools.hideLabel(form, '#testName');
                tools.hideLabel(form, '#testScore');
                tools.hideLabel(form, '#remarkAdd');
                $("#remarkAdd").removeClass("jqx-validator-error-element");
                $(".jqx-validator-hint").remove();
            });
            $("#addModal").on("shown.bs.modal", function () {
                $("#proModal").prop("disabled", true).trigger("chosen:updated");
                $("#typeModal").prop("disabled", true).trigger("chosen:updated");
            });
            $("#editModal").on("shown.bs.modal", function () {
                $("#proModalEdit").prop("disabled", true).trigger("chosen:updated");
            });

            $("#editModal").on("hidden.bs.modal", function () {
                var form = $("#editForm");
                tools.hideLabel(form, '#proModalEditInput');
                tools.hideLabel(form, '#typeModalEditInput');
                tools.hideLabel(form, '#testNameEdit');
                tools.hideLabel(form, '#testScoreEdit');
                tools.hideLabel(form, '#remarkEdit');
                $("#remarkEdit").removeClass("jqx-validator-error-element");
                $(".jqx-validator-hint").remove();
            });
            $("#addTypeModal").on("hidden.bs.modal", function () {
                var form = $("#addTypeForm");
                tools.hideLabel(form, '#proTypeModalAddInput');
                tools.hideLabel(form, '#modelTypeName');
                $("#remarkTypeAdd").removeClass("jqx-validator-error-element");
                $(".jqx-validator-error-label").remove();
            });
            $(".form-horizontal").on("click", "#radio_box input", function () {
                $(this).prop("checked", true);
                $(this).siblings("input").prop("checked", false);
            })

        },
        hideLabel: function (form, input) {
            form.jqxValidator('hideHint', input);
        },
        getConfig: function () {
            tools.ruleUrl = bs.getSysConfig("GZGL_URL").value;
            var maxNum = bs.getSysConfig("NAME_LIMIT");
            var num = 50;
            if (maxNum.value) {
                num = maxNum.value
            }
            tools.maxTextLength = num;
        },
        selectInit: function () {
            bs.dataTime("#start", "#end");
            bs.dataTime("#startRule", "#endRule", "YYYY-MM-DD");
            bs.dataTime("#startS", "#endS", "YYYY-MM-DD");
            bs.dataTime("#startUp", "#endUp", "YYYY-MM-DD");
            tools.selectProvince();
            tools.getState();
            tools.getStateRule();
            tools.getTestState();
            tools.getRuleattributes();
            tools.getFatal();
            tools.getScoreFlag();
            bs.selectDown($("#modelTypeEdit"), tools.classifyArr, "", '100%');
            bs.selectDown($("#typeParentModal"), tools.classifyArr, "", "100%");
            bs.selectDown($("#tagTypeCopy"), tools.classifyArr, "", "100%");
            tools.selectChange($("#typeParentModal"), $("#typeParentModalAddInput"));
            tools.selectChange($("#proTypeModal"), $("#proTypeModalAddInput"));
            tools.selectChange($("#proModal"), $("#proModalAddInput"));
            tools.selectChange($("#typeModal"), $("#typeModalAddInput"));
            tools.selectChange($("#proModalEdit"), $("#proModalEditInput"));
            tools.selectChange($("#modelTypeEdit"), $("#typeModalEditInput"));
            tools.selectChange($("#proTypeModalCopy"), $("#proTypeModalAddInputCopy"));
            tools.selectChange($("#tagTypeCopy"), $("#tagTypeAddInputCopy"));
            tools.getSeatId(tools.getIdInCode($("#pro").val()));
            $("#pro").on("change", function (event, sel) {//根据省份渲染分类信息
                tools.getSeatId(tools.getIdInCode($("#pro").val()));
                $("#person").val("");
            });
            $("#proModal").on("change", function (event, sel) {//根据省份渲染分类信息
                if (sel.selected !== "") {
                    $("#typeModalAddInput").val("");
                    tools.selectType(sel.selected, $("#typeModal"), "");
                }
            });
            $("#proModalEdit").on("change", function (event, sel) {//根据省份渲染分类信息
                if (sel.selected !== "") {
                    $("#typeModalEditInput").val("");
                    tools.selectType(sel.selected, $("#modelTypeEdit"), "");
                }
            });
            $("#proTypeModalCopy").on("change", function (event, sel) {//根据省份渲染分类信息
                if (sel.selected !== "") {
                    $("#tagTypeAddInputCopy").val("");
                    tools.selectType(sel.selected, $("#tagTypeCopy"), "");
                }
            });
        },
        selectChange: function ($elem, $input) {
            $elem.on("change", function (event, sel) {
                $input.val(sel.selected);
                if (sel.selected == "") {
                    $input.next().html("").css("display", "none !important");
                }
            });
        },
        getState: function () {
            tools.stateArr = bs.getDownData("sys_post_status");
            bs.selectDown($("#state"), tools.stateArr);
        },
        getStateRule: function () {
            tools.stateArr.shift();
            tools.stateArr.unshift({"name": "请选择", "value": ""});
            bs.selectDown($("#stateRule"), tools.stateArr);
        },
        getScoreFlag: function () {
            tools.scoreFlagArr = bs.getDownData("score_flag");
            tools.scoreFlagArr.shift();
            tools.scoreFlagArr.unshift({"name": "请选择", "value": ""});
            bs.selectDown($("#scoreFlag"), tools.scoreFlagArr);
        },
        getRuleattributes: function () {
            tools.ruleattributesArr = bs.getDownData("rule_property");
            tools.ruleattributesArr.shift();
            tools.ruleattributesArr.unshift({"name": "请选择", "value": ""});
            bs.selectDown($("#ruleattributes"), tools.ruleattributesArr);
        },
        getTestState: function () {
            tools.testStateArr = bs.getDownData("model_is_test");
        },
        getFatal: function () {
            tools.fatalArr = bs.getDownData("rule_nature");
            tools.fatalArr.shift();
            bs.selectDown($("#rulefatal"), tools.fatalArr);
        },
        tabSearch: function () {
            var search = $(".search");
            $("#btnSearch").on("click", function () {
                if (search.hasClass("on")) {
                    search.slideUp();
                    search.removeClass("on");
                    $("#btnSearch").html('<i class="fa fa-filter"></i> 查询').attr("title", "显示查询条");
                } else {
                    search.slideDown();
                    search.addClass("on");
                    $("#btnSearch").html('<i class="fa fa-filter"></i> 隐藏').attr("title", "隐藏查询条");
                }

            });
        },
        search: function () {
            $("#search").on("click", function () {
                tools.tableRefresh();
            });
            $("#searchAll").on("click", function () {
                $("#classify").val("");
                var opLength = $("#pro").find("option").length;
                if (opLength > 2) {
                    tools.updataSelect($("#pro"), "");
                }
                $("#jstree").jstree("deselect_all", true);
                tools.tableRefresh();
            });
            $("#searchRule").on("click", function () {
                tools.tableRefreshRule();
            });
            $("#searchAllRule").on("click", function () {
                $("#classifyRule").val("").attr("data-id", $("#idservice").val());
                $("#jstreeRule").jstree("deselect_all", true);
                tools.tableRefreshRule();
            });
            $("#addRuleModel").on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    //此处编写用户敲回车后的代码
                    tools.tableRefreshRule();
                }
            })
        },
        tableRefreshRule: function () {
            $("#tableRule").bootstrapTable('refreshOptions', {pageNumber: 1});
            $("#tableRule").bootstrapTable('refresh');
        },
        tableRefresh: function () {
            $("#myTable").bootstrapTable('refreshOptions', {pageNumber: 1});
            $("#myTable").bootstrapTable('refresh');
        },
        enterSearch: function () {
            $("body").on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    //此处编写用户敲回车后的代码
                    tools.tableRefresh();
                }
            })
        },
        reset: function () {
            $("#reset").on("click", function () {
                bs.resetSearch($(".search"), ["pro"]);
                if($("#spanId",parent.document).attr("data-procode")==""){
                    $("#pro").val("").trigger("chosen:updated");
                }
                if ($("#laydate_box").length > 0) {
                    bs.resetTimeElems("#start", "#end");
                }
                tools.tableRefresh();
            })
            $("#resetRule").on("click", function () {
                bs.resetSearch($("#addRuleModel .search"), ["classifyRule"]);
                if ($("#laydate_box").length > 0) {
                    bs.resetTimeElems("#startRule", "#endRule", "#startS", "#endS", "#startUp", "#endUp");
                }
                tools.tableRefreshRule();
            })
        },
        resetSelect: function ($obj) {
            $obj.val("");
            $obj.trigger("chosen:updated");
        },
        refresh: function () {
            $("#refresh").on("click", function () {
                $("#myTable").bootstrapTable('refresh');
            })
        },
        selectProvince: function () {//省份下拉框初始化
            tools.proArr = bs.getProvince();
            var arr = tools.proArr;
            arr.shift();
            arr.unshift({name: "请选择", value: "", id: ""})
            bs.selectDown($("#proModal"), arr, "", '100%');
            bs.selectDown($("#proModalEdit"), arr, "", "100%");
            bs.selectDown($("#proTypeModal"), arr, "", "100%");
            bs.selectDown($("#proTypeModalCopy"), arr, "", "100%");

            bs.selectDown($("#pro"), tools.proArr, "");
        },
        getSeatId: function (areaId) {//获取创建人数据
            tools.seatAllArr = bs.getGreatPerson("/rest/searchUser/searchModelUser", "",{"areaId":areaId});
            var arr=[];
            for(var i=0;i<tools.seatAllArr.length;i++){
                var userName=tools.seatAllArr[i].userName;
                if(userName){
                    arr.push(userName)
                }
            }
            $("#person").autocomplete({
                source: arr
            });
        },
        addModel: function () {
            $("#btnAdd").on("click", function () {
                var ref = $('#jstree').jstree(true);//获得整个树
                var sel = ref.get_selected(); //获得所有选中节点，返回值为数组
                var children = $('#jstree').jstree("get_node", sel).children;//获得子节点
                if ((sel.length <= 0) || (sel[0] == "-9999") || (children.length > 0)) {
                    toastrCog.error("请选择一个分类", 3000);
                    return
                }
                var parents = $('#jstree').jstree("get_node", sel).parents;//获得父节点
                var proId = Math.abs(parents[parents.length - 3]);//获得父节点（省份id）;
                var oTable1 = new TableInit1($("#addRuleTable .fixed-table-body table"), []);
                oTable1.Init($("#addRuleTable .fixed-table-body table"), []);
                $("#addModal").modal("show");
                $("#addModelForm")[0].reset();
                tools.updataSelect($("#proModal"), tools.getCodeInId(proId));
                $("#proModalAddInput").val(tools.getCodeInId(proId));
                tools.selectType(tools.getCodeInId(proId), $("#typeModal"), "");
                tools.updataSelect($("#typeModal"), sel);
                $("#typeModalAddInput").val(sel);
                tools.ruleTableData=[];
            })
        },
        saveModel: function () {
            $("#save").on("click", function () {
                $("#addModelForm").jqxValidator("validate");
            });
            $("#addModelForm").on("validationSuccess", function (event) {
                if ($(".jqx-validator-hint").length > 0) {
                    return
                }
                var isV=true;
                $("#scoreForm .oneNum").each(function(){
                    if(!$(this).prop("disabled") && $(this).val()==""){
                        toastrCog.error("单次分值不能为空！");
                        isV=false;
                        return
                    }
                });
                if(isV){
                    var obj = {};
                    obj.provincecode = $("#proModalAddInput").val();
                    obj.typeid = $("#typeModalAddInput").val();
                    obj.name = $("#testName").val();
                    obj.fullscore = $("#testScore").val();
                    obj.note = $("#remarkAdd").val();
                    for (var i = 0; i < tools.ruleTableData.length; i++) {
                        delete tools.ruleTableData[i].id;
                    }
                    obj.modelrulelist = bs.objArrDeepCopy(tools.ruleTableData);
                    $("#save").html("请求中...请稍后").prop("disabled", true);
                    $.ajax({
                        url: basePath + "rest/model/insert/modelByExample",
                        type: "post",
                        data: JSON.stringify(obj),
                        contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                        success: function (result) {
                            var msg = result.msg;
                            if (result.code != 0) {
                                toastrCog.error(msg, 3000)
                            } else {
                                $("#myTable").bootstrapTable('refresh');
                            }
                            $("#addModal").modal("hide");
                        },
                        error: function () {

                        },
                        complete: function () {
                            $("#save").html("保存").prop("disabled", false);
                        }
                    });
                }
            });
        },
        changeform: function () {
            $("#addModelForm").change(function () {
                $("#save").attr("disabled", false);
            });
        },
        editModel: function () {
            $("#editModal").on("hide.bs.modal", function () {
                tools.modelSelectArr = [];
            });
            $("#btnEdit").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要编辑的数据！", 3000);
                } else if (selectArr.length > 1) {
                    toastrCog.error("请选择一条要编辑的数据！", 3000);
                } else if (selectArr[0].poststatus == 1) {
                    toastrCog.error("模型已上线，无法编辑。要编辑模型,请先下线模型。", 3000);
                } else {
                    $("#editModal").modal("show");
                    bs.loadFormData($("#editForm"), selectArr[0]);
                    $("#proModalEdit").trigger("chosen:updated");
                    $("#proModalEditInput").val(selectArr[0].provincecode);
                    tools.selectType(selectArr[0].provincecode, $("#modelTypeEdit"), "");
                    $("#modelTypeEdit").val(selectArr[0].typeid);
                    $("#modelTypeEdit").trigger("chosen:updated");
                    $("#typeModalEditInput").val(selectArr[0].typeid);
                    $("#editModal").attr("data-id", selectArr[0].id);
                    tools.modelSelectArr = selectArr;
                    tools.ruleTableData = [];
                    var ruleArr = selectArr[0].modelrulelist;
                    tools.ruleTableData = bs.objArrDeepCopy(ruleArr);//对象深层拷贝
                    tools.rootRuleData(tools.ruleTableData, $("#ruleBoxEdit"));
                }
            });
            $("#saveEdit").on("click", function () {
                $("#editForm").jqxValidator("validate");
            });
            $("#editForm").on("validationSuccess", function (event) {
                if ($(".jqx-validator-hint").length > 0) {
                    return
                }
                var isV=true;
                $("#scoreFormEdit .oneNum").each(function(){
                    if(!$(this).prop("disabled") && $(this).val()==""){
                        toastrCog.error("单次分值不能为空！");
                        isV=false;
                        return
                    }
                });
                if(isV){
                    var id = $("#editModal").attr("data-id");
                    var params = {
                        id: id,
                        provincecode: $("#proModalEditInput").val(),
                        typeid: $("#modelTypeEdit").val(),
                        name: $("#testNameEdit").val(),
                        fullscore: $("#testScoreEdit").val(),
                        note: $("#remarkEdit").val()
                    };
                    for (var i = 0; i < tools.ruleTableData.length; i++) {
                        delete tools.ruleTableData[i].id;
                        tools.ruleTableData[i].modelid = parseInt(id);
                    }
                    params.modelrulelist = tools.ruleTableData;
                    $("#saveEdit").html("请求中...请稍后").prop("disabled", true);
                    $.ajax({
                        type: "post",
                        url: basePath + "/rest/model/update/modelByExampleSelective",
                        dataType: "json",
                        contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                        data: JSON.stringify(params),
                        success: function (data) {
                            if (data.code == 0) {
                                $("#myTable").bootstrapTable('refresh');
                                toastrCog.success(data.msg, 1000)
                            } else {
                                toastrCog.error(data.msg, 3000)
                            }
                            $("#editModal").modal("hide");
                        },
                        complete: function () {
                            $("#saveEdit").html("保存").prop("disabled", false);
                        }
                    })
                }
            });
        },
        rootRuleData: function (ruleArr, $elem) {
            var $box = $elem.find(".rule_box");
            var table = $box.find("table");
            if (ruleArr && ruleArr.length > 0) {
                var oTable1 = new TableInit1(table, ruleArr);
                oTable1.Init(table, ruleArr);
            } else {
                var oTable1 = new TableInit1(table, []);
                oTable1.Init(table, []);
            }
        },
        delModel: function () {
            $("#btnDel").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var delArr = [];//用来存放已上线数据
                var delTaskArr = [];//用来存放被任务使用的数据
                var taskArr = [//用来存放任务状态的数据
                    {"code": "0", "value": []},
                    {"code": "12", "value": []},
                    {"code": "3", "value": []},
                    {"code": "4", "value": []}
                ];
                for (var i = 0; i < selectArr.length; i++) {
                    if (selectArr[i].poststatus == 1) {
                        delArr.push(selectArr[i]);//用来存放已上线数据
                    }
                }
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要删除的数据！", 3000);
                } else if (delArr.length > 0) {
                    toastrCog.error("所选的数据包含已上线的模型，请重新选择！", 3000);
                } else {
                    var ids = [];
                    for (var i = 0; i < selectArr.length; i++) {
                        ids.push(selectArr[i].id);
                    }
                    $.ajax({
                        type: "post",
                        url: basePath + "rest/model/query_model_task_status",
                        dataType: "json",
                        contentType: 'application/json', //contentType很重要
                        data: JSON.stringify({ids: ids}),
                        async: false,
                        success: function (data) {
                            if (data.code == "0") {
                                var res = data.data;
                                for (var i = 0; i < res.length; i++) {
                                    var modelName = res[i].model_name;
                                    var taskName = res[i].task_name;
                                    var taskStatus = res[i].task_status;
                                    var taskId = res[i].task_id;
                                    delTaskArr.push(modelName);//保存被任务使用的数据
                                    if (taskStatus == "1" || taskStatus == "2") {//任务质检中
                                        taskArr[1].value.push({
                                            "modelName": modelName,
                                            "taskName": taskName,
                                            "taskId": taskId
                                        });
                                    } else if (taskStatus == "3") {//任务质检完成
                                        taskArr[2].value.push({
                                            "modelName": modelName,
                                            "taskName": taskName,
                                            "taskId": taskId
                                        });
                                    } else if (taskStatus == "4") {//任务停止
                                        taskArr[3].value.push({
                                            "modelName": modelName,
                                            "taskName": taskName,
                                            "taskId": taskId
                                        });
                                    } else {//任务未启动
                                        taskArr[0].value.push({
                                            "modelName": modelName,
                                            "taskName": taskName,
                                            "taskId": taskId
                                        });
                                    }
                                }
                            }
                        }
                    });
                    if (delTaskArr.length > 0) {//如果被任务使用
                        var tipStr = "";
                        if (taskArr[1].value.length > 0) {//任务质检中
                            var arr1 = tools.groupJson(taskArr[1].value);
                            tipStr = tools.tipStr(arr1, "1", "删除");
                            toastrCog.error(tipStr, 3000);
                        } else if ((taskArr[2].value.length > 0) || (taskArr[3].value.length > 0)) {//任务质检完成、 停止
                            var arr2 = taskArr[2].value;
                            var arr3 = taskArr[3].value;
                            var arr4 = arr2.concat(arr3);
                            $.ajax({
                                type: "post",
                                url: basePath + 'rest/per-task/get-task-expir-date-by-del',
                                dataType: "json",
                                data: {
                                    id: tools.getStr(arr4, "taskId"),
                                    modelName: tools.getStr(arr4, "modelName"),
                                    workName: tools.getStr(arr4, "taskName")
                                },
                                success: function (result) {
                                    if (result.code == "-1") {
                                        toastrCog.error(result.msg, 3000);
                                    } else {
                                        arr4 = tools.groupJson(arr4);
                                        tipStr = tools.tipStr(arr4, "2", "删除");
                                        tools.delTipRender(selectArr);
                                        $("#delModal .tipBox").html(tipStr);
                                    }
                                }
                            });
                        } else {
                            var arr0 = tools.groupJson(taskArr[0].value);
                            tipStr = tools.tipStr(arr0, "0", "删除");
                            tools.delTipRender(selectArr);
                            $("#delModal .tipBox").html(tipStr);
                        }
                    } else {
                        var ids = tools.getStr(selectArr, "id");
                        $.ajax({
                            type: "GET",
                            url: basePath + 'rest/model/checkDelete/modelByExample',
                            dataType: "json",
                            data: {
                                ids: ids
                            },
                            success: function (result) {
                                var msg = result.msg;
                                if (result.code == 0) {
                                    tools.delTipRender(selectArr);
                                } else if (result.code == 2) {
                                    toastrCog.error(msg, 3000);
                                }
                            }
                        });
                    }

                }
            });
            $("#delBtn").on("click", function () {
                $("#delBtn").html("请求中...请稍后").prop("disabled", true);
                var id = $("#delModal").attr("data-id");
                $.ajax({
                    type: "get",
                    url: basePath + "/rest/model/delete/modelByExample",
                    dataType: "json",
                    contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                    data: {
                        ids: id
                    },
                    success: function (data) {
                        if (data.code == 0) {
                            $("#myTable").bootstrapTable('refresh');
                            toastrCog.success(data.msg, 1000)
                        } else {
                            toastrCog.error(data.msg, 3000)
                        }
                        $("#delModal").modal("hide");
                    },
                    complete: function () {
                        $("#delBtn").html("确定").prop("disabled", false);
                    }
                })
            });
        },
        startModel: function () {
            $("#btnStart").on("click", function () {
                $("#startModal .tipBox").html("");
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var startArr = [];//用来存放已上线数据
                var stopArr = [];//用来存放未上线数据
                var noRuleArr = [];//用来存放没有规则的数据
                var noRuleStatusArr = [];//用来存放规则未上线的数据

                for (var i = 0; i < selectArr.length; i++) {
                    if (selectArr[i].poststatus == 1) {
                        startArr.push(selectArr[i]);//保存已上线的数据
                    } else {
                        stopArr.push(selectArr[i]);//保存已上线的数据
                    }
                }
                if (startArr.length <= 0) {
                    var param = [];
                    for (var i = 0; i < stopArr.length; i++) {
                        var obj = {};
                        obj.modelName = stopArr[i].name;
                        obj.ruleIds = [];
                        var ruleList = stopArr[i].modelrulelist;
                        if (ruleList && ruleList.length > 0) {
                            for (var j = 0; j < ruleList.length; j++) {
                                var id = ruleList[j].ruleid;
                                if (obj.ruleIds.indexOf(id) == "-1") {
                                    obj.ruleIds.push(id);
                                }
                            }
                        } else if (ruleList.length == 0) {
                            noRuleArr.push(stopArr[i]);//保存没有规则的数据
                        }
                        param.push(obj);
                    }
                }
                if (selectArr.length <= 0) {//如果没有选择数据
                    toastrCog.error("请选择要上线的数据！", 3000);
                } else if (startArr.length > 0) {//如果选择了已上线的数据
                    toastrCog.error("所选模型包含已上线 " + tools.getStr(startArr, "name") + " 模型，请重新选择！", 3000);
                } else if (noRuleArr.length > 0) {//如果选择了没有规则的数据
                    toastrCog.error("模型" + tools.getStr(noRuleArr, "name") + " 没有选择规则，不能上线！若需要上线，请先选择规则！", 3000);
                } else {
                    var str = "";
                    $.ajax({
                        type: "post",
                        url: "/qualityinspection/combinationRule/listcombrulebyids",
                        data: JSON.stringify(param),
                        contentType: "application/json",
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            var res = data.data;
                            for (var i = 0; i < res.length; i++) {
                                var name = res[i].modelName;
                                var rules = res[i].rules;
                                var rulenames = "";
                                for (var j = 0; j < rules.length; j++) {
                                    var status = rules[j].status;
                                    var rulename = rules[j].rulename;
                                    if (status == "0") {
                                        rulenames += rulename + ","
                                    }
                                }
                                rulenames = rulenames.substr(0, rulenames.length - 1);
                                if (rulenames != "") {
                                    str += "模型 " + name + " 使用的规则 " + rulenames + " 未上线,"
                                }
                            }
                        }
                    });
                    if (str != "") {//如果选择了未上线规则的数据
                        str += "不能上线！若需要上线，请先上线未上线的规则或从模型中删除这些规则！";
                        toastrCog.error(str, 3000);
                    } else {
                        tools.tipRender(1, selectArr, "上线");
                    }
                }
            });
            $("#startBtn").on("click", function () {
                $("#startBtn").html("请求中...请稍后").prop("disabled", true);
                var id = $("#startModal").attr("data-id");
                var code = $("#startModal").attr("data-code");
                var url = "";
                if (code == 0) {
                    url = basePath + "/rest/model/offline/model"
                } else if (code == 1) {
                    url = basePath + "/rest/model/online/model"
                }
                $.ajax({
                    type: "post",
                    url: url,
                    dataType: "json",
                    data: {
                        ids: id
                    },
                    success: function (data) {
                        if (data.code == 0) {
                            $("#myTable").bootstrapTable('refresh');
                            toastrCog.success(data.msg, 1000)
                        } else {
                            toastrCog.error(data.msg, 3000)
                        }
                        $("#startModal").modal("hide");
                    },
                    complete: function () {
                        $("#startBtn").html("确定").prop("disabled", false);
                    }
                })
            });
        },
        stopModel: function () {
            $("#btnStop").on("click", function () {
                $("#startModal .tipBox").html("");
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var stopArr = [];//用来存放未上线数据
                var stopTaskArr = [];//用来存放被任务使用的数据
                var taskArr = [//用来存放任务状态的数据
                    {"code": "0", "value": []},
                    {"code": "12", "value": []},
                    {"code": "3", "value": []},
                    {"code": "4", "value": []}
                ];
                for (var i = 0; i < selectArr.length; i++) {
                    if (selectArr[i].poststatus == 0) {
                        stopArr.push(selectArr[i]);//保存未上线的数据
                    }
                }
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要下线的数据！", 3000);
                } else if (stopArr.length > 0) {
                    toastrCog.error("所选的数据包含未上线的模型，请重新选择！", 2000);
                } else {
                    var ids = [];
                    for (var i = 0; i < selectArr.length; i++) {
                        ids.push(selectArr[i].id);
                    }
                    $.ajax({
                        type: "post",
                        url: basePath + "rest/model/query_model_task_status",
                        dataType: "json",
                        contentType: 'application/json', //contentType很重要
                        data: JSON.stringify({ids: ids}),
                        async: false,
                        success: function (data) {
                            if (data.code == "0") {
                                var res = data.data;
                                for (var i = 0; i < res.length; i++) {
                                    var modelName = res[i].model_name;
                                    var taskName = res[i].task_name;
                                    var taskStatus = res[i].task_status;
                                    var taskType = res[i].workType;
                                    stopTaskArr.push(modelName);//保存被任务使用的数据
                                    if (taskStatus == "1" || taskStatus == "2") {//任务质检中
                                        taskArr[1].value.push({
                                            "modelName": modelName,
                                            "taskName": taskName,
                                            "taskType": taskType
                                        });
                                    } else if (taskStatus == "3") {//任务质检完成
                                        taskArr[2].value.push({
                                            "modelName": modelName,
                                            "taskName": taskName,
                                            "taskType": taskType
                                        });
                                    } else if (taskStatus == "4") {//任务停止
                                        taskArr[3].value.push({
                                            "modelName": modelName,
                                            "taskName": taskName,
                                            "taskType": taskType
                                        });
                                    } else {//任务未启动
                                        taskArr[0].value.push({
                                            "modelName": modelName,
                                            "taskName": taskName,
                                            "taskType": taskType
                                        });
                                    }
                                }
                            }
                        }
                    });
                    if (stopTaskArr.length > 0) {//如果被任务使用
                        var tipStr = "";
                        if ((taskArr[1].value.length > 0) || (taskArr[2].value.length > 0) || (taskArr[3].value.length > 0)) {//任务质检中
                            var arr1 = tools.groupJson(taskArr[1].value);
                            var arr2 = taskArr[2].value;
                            var arr3 = taskArr[3].value;
                            var arr4 = tools.groupJson(arr2.concat(arr3));
                            tipStr += tools.tipStr(arr1, "1", "下线");
                            tipStr += tools.tipStr(arr4, "2", "下线");
                            toastrCog.error(tipStr, 3000);
                        }
//                        else if ((taskArr[2].value.length > 0) || (taskArr[3].value.length > 0)) {//任务质检完成、 停止
//                            var arr2 = taskArr[2].value;
//                            var arr3 = taskArr[3].value;
//                            var arr4 = tools.groupJson(arr2.concat(arr3));
//                            tipStr = tools.tipStr(arr4, "2", "下线");
//                            tools.tipRender(0, selectArr, "下线");
//                            $("#startModal .tipBox").html(tipStr);
//                        }
                        else {//任务未启动
                            var arr0 = tools.groupJson(taskArr[0].value);
                            tipStr = tools.tipStr(arr0, "0", "下线");
                            tools.tipRender(0, selectArr, "下线");
                            $("#startModal .tipBox").html(tipStr);
                        }
                    } else {//如果没有被任务使用，则可以下线
                        tools.tipRender(0, selectArr, "下线");
                    }
                }
            });
        },
        delTipRender: function (selectArr) {
            var modalElem = $("#delModal");
            modalElem.modal("show");
            $("#delName").html("您确定要删除所选的" +
                "<span style='color:rgb(50, 136, 226)'>" + selectArr.length + "</span>" +
                "个模型" +
                "<span style='color:rgb(50, 136, 226)'>" + tools.getStr(selectArr, "name") + "</span>吗？");
            modalElem.attr("data-id", tools.getStr(selectArr, "id"));
        },
        tipRender: function (type, selectArr, title) {
            var modalElem = $("#startModal");
            modalElem.modal("show");
            modalElem.find(".modal-title").html(title);
            $("#type").html(
                "确定要" + title + "所选的" +
                "<span style='color:rgb(50, 136, 226)'>" + selectArr.length + "</span>" +
                "个模型" +
                "<span style='color:rgb(50, 136, 226)'>" + tools.getStr(selectArr, "name") + "</span>吗？");
            modalElem.attr("data-id", tools.getStr(selectArr, "id"));
            modalElem.attr("data-code", type);
        },
        tipStr: function (arr1, code, str) {//模型删除/上线/下线提示
            var tipStr = ""
            for (var i = 0; i < arr1.length; i++) {
                var modelName = arr1[i].modelName;
                var dataTask = arr1[i].data;
                var taskNameStr = "";
                var modelTestStr = "";
                for (var j = 0; j < dataTask.length; j++) {
                    if (dataTask[j].taskType != 2) {
                        taskNameStr += dataTask[j].taskName + ","
                        modelTestStr += "1";
                    } else {
                        modelTestStr += "0";
                    }
                }

                taskNameStr = taskNameStr.substr(0, taskNameStr.length - 1);
                if (code == "1") {
                    if (modelTestStr.indexOf("1") < 0) {
                        tipStr += "<div>模型 [" + modelName + "] 不能" + str + "，因为其已被[模型测检]使用，并且正在测检中。</div>"
                    } else {
                        tipStr += "<div>模型 [" + modelName + "] 不能" + str + "，因为其已被质检任务 [" + taskNameStr + "] 使用，并且该任务正在质检。</div>"
                    }
                    ;
                } else if (code == "2") {
                    tipStr += "<div>模型 [" + modelName + "] 被质检任务 [" + taskNameStr + "] 使用，并且已经产生质检结果。</div>"
                } else if (code == "0") {
                    tipStr += "<div>模型 [" + modelName + "] 被质检任务 [" + taskNameStr + "] 使用，</div>"
                }

            }
            return tipStr
        },
        groupJson: function (arr) {//按照某个属性分组
            var map = {},
                dest = [];
            for (var i = 0; i < arr.length; i++) {
                var ai = arr[i];
                if (!map[ai.modelName]) {
                    dest.push({
                        modelName: ai.modelName,
                        data: [ai]
                    });
                    map[ai.modelName] = ai;
                } else {
                    for (var j = 0; j < dest.length; j++) {
                        var dj = dest[j];
                        if (dj.modelName == ai.modelName) {
                            dj.data.push(ai);
                            break;
                        }
                    }
                }
            }
            return dest
        },
        copyModel: function () {
            $("#btnCopy").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要复制的数据！", 1000);
                } else {
                    var ulBox = $(".nameList");
                    ulBox.html("");
                    menu.renderO($("#jsTreeCopy"));
                    $("#copyModal").modal("show");
//                  渲染模型修改名称列表
                    for (var i = 0; i < selectArr.length; i++) {
                        var id = selectArr[i].id;
                        var name = selectArr[i].name;
                        var li = $('<li>' +
                            '<input type="text" class="oldName form-control" value="' + name + '" data-id="' + id + '" disabled>' +
                            '<span class="fa fa-long-arrow-right"></span>' +
                            '<input type="text" class="newName form-control" value="' + name + '（复制）" id="new' + i + '">' +
                            '</li>');
                        ulBox.append(li);
                        validateFun.initKeyValidatorCopy('#new' + i);
                    }
                    $("#copyModal").on("hidden.bs.modal", function () {
                        $(".jqx-validator-hint").remove();
                        $(".ceng").show();
                        $(".ceng").next().hide();
                        $("#searchMenuCopy").prev().val("");
                    });
                }
            });
            $("#copyBtn").on("click", function () {
                $("#copyForm .newName").focus();
                $("#copyForm .newName").blur();
                if ($(".jqx-validator-hint").length <= 0) {
                    var params = {};
                    var ref = $('#jsTreeCopy').jstree(true);//获得整个树
                    var sel = ref.get_selected(); //获得所有选中节点，返回值为数组
                    var pro = $('#jsTreeCopy').jstree("get_node", sel).original.provincecode;
                    params.provinceCode = pro;
                    params.typeId = sel[0];
                    params.models = [];
                    $(".nameList li").each(function () {
                        var obj = {};
                        var id = parseInt($(this).find(".oldName").attr("data-id"));
                        var name = $(this).find(".newName").val();
                        obj.id = id;
                        obj.name = name;
                        params.models.push(obj);
                    });
                    $("#copyBtn").html("请求中...请稍后").prop("disabled", true);
                    $.ajax({
                        type: "post",
                        url: basePath + "/rest/model/copy/models",
                        dataType: "json",
                        contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                        data: JSON.stringify(params),
                        success: function (data) {
                            if (data.code == 0) {
                                tools.tableRefresh();
                                toastrCog.success(data.msg, 1000);
                                $("#copyModal").modal("hide");
                            } else {
                                toastrCog.error(data.msg, 2000)
                            }

                        },
                        complete: function () {
                            $("#copyBtn").html("确定").prop("disabled", false);
                        }
                    })
                }
            });
        },
        export: function () {
            $("#export").on("click", function () {
                if (tools.tableData.length == 0) {
                    toastrCog.error("没有可导出的数据哦！")
                    return;
                }
                var form = $("#exportForm");
                form.attr("action", basePath + "/rest/model/download/modelInfo");
                $("#provincecodeE").val($("#pro").val().trim());
                $("#nameE").val($("#modelname").val().trim());
                $("#typeidE").val($("#classify").val().trim());
                $("#stateE").val($("#state").val().trim());
                $("#startE").val($("#start").val().trim());
                $("#endE").val($("#end").val().trim());
                $("#personE").val(bs.getXInY(tools.seatAllArr, "id", "userName", $("#person").val()));
//                window.open(basePath+"/rest/model/download/modelInfo?"+JSON.stringify(form.serialize()))
                form[0].submit();
            })

        },
        updataSelect: function ($obj, val) {
            $obj.val(val);
            $obj.trigger("chosen:updated");
        },
        selectType: function (code, $elem, selfId) {
            var typeArr = [];
            $.ajax({
                url: basePath + "rest/model/select/modelTypeByExample",
                type: "post",
                async: false,
                data: {
                    provincecode: code,
                    selfId: selfId
                },
                success: function (data) {
                    var data = data.data;
                    for (var i = 0; i < data.length; i++) {
                        var province = {name: "", value: ""};
                        province.name = data[i]['name'];
                        province.value = data[i]['id'];
                        typeArr.push(province);
                    }
                    bs.selectDown($elem, typeArr, "", "100%");
                },
                error: function () {
                    typeArr.push({name: "查询省份错误！", value: ""});
                    bs.selectDown($elem, typeArr, "", '100%');
                }
            });
        },
        getCodeInId: function (id) {//根据省份id获取code
            var value = "";
            for (var i = 0; i < tools.proArr.length; i++) {
                if (tools.proArr[i].id == id) {
                    value = tools.proArr[i].value;
                    break;
                }
            }
            return value;
        },
        getIdInCode: function (code) {//根据省份id获取code
            var id = "";
            for (var i = 0; i < tools.proArr.length; i++) {
                if (tools.proArr[i].value == code) {
                    id = tools.proArr[i].id;
                    break;
                }
            }
            return id;
        },
        getStr: function (selectArr, code) {
            var str = "";
            for (var i = 0; i < selectArr.length; i++) {
                str += selectArr[i][code] + ",";
            }
            str = str.substr(0, str.length - 1);
            return str;
        }
    };
    var modelType = {
        init: function () {
            modelType.add();
        },
        add: function () {
            $("#addType").on("click", function () {
                $("#typeParentModal").parents(".form-group").hide();
                $("#addTypeModal").modal("show");
                $("#addTypeModal").attr("data-id", "");
                $("#addTypeModal").attr("data-code", "add");
                $("#addTypeForm").find(".modal-title").html("添加分类");
                $("#addTypeForm")[0].reset();
                $("#proTypeModal").prop("disabled", false);
                tools.updataSelect($("#proTypeModal"), "");
            });
            $("#addTypeBtn").on("click", function () {
                $("#addTypeForm").jqxValidator("validate");
            });
            $("#addTypeForm").on("validationSuccess", function (event) {
                var url = "";
                var code = $("#addTypeModal").attr("data-code");
                var params;
                if (code == "add") {
                    url = basePath + 'rest/model/insert/modelTypeByExample';
                    if ($("#typeParentModal").parents(".form-group").css("display") == "block") {
                        parentid = $("#typeParentModal").val()
                    } else {
                        parentid = $("#addTypeModal").attr("data-id")
                    }
                    params = {
                        "parentid": parentid,
                        "name": $("#modelTypeName").val(),
                        "provincecode": $("#proTypeModal").val(),
                        "note": $("#remarkTypeAdd").val()
                    };
                } else if (code == "edit") {
                    url = basePath + "rest/model/update/modelTypeByExample";
                    var parentid = "";
                    if ($("#typeParentModal").parents(".form-group").css("display") == "block") {
                        parentid = $("#typeParentModal").val()
                    } else {
                        parentid = ""
                    }
                    params = {
                        id: $("#addTypeModal").attr("data-id"),
                        name: $("#modelTypeName").val(),
                        note: $("#remarkTypeAdd").val(),
                        parentid: parentid
                    };
                }
                $.ajax({
                    type: "GET",
                    url: url,
                    dataType: "json",
                    data: params,
                    success: function (result) {
                        var msg = result.msg;
                        if (result.code != 0) {
                            toastrCog.error(msg, 1000)
                        } else {
                            menu.refresh();
//                            $("#myTable").bootstrapTable("refresh");
                        }
                        $("#addTypeModal").modal("hide");
                    }
                });
            });
        }
    };
    var draggables = { //模态框拖动
        init: function () {
            this.draggable($('.modal').not("#addRuleModel"));
        },
        draggable: function (obj) {
            $(obj).draggable();
        }
    };
    var rule = {
        oldRuleDataArr:[],
        init: function () {
            rule.addRule();
            rule.delRule($("#addRuleTable"));
            rule.delRule($("#ruleBoxEdit"));
        },
        addRule: function () {
            $("#addRule,#editRule").on("click", function () {
                var pro = "";
                if ($(this).attr("id") == "addRule") {
                    $("#addRuleBtn").attr("data-code", "addRule");
                    pro = $("#proModal").val();
                } else {
                    $("#addRuleBtn").attr("data-code", "editRule");
                    pro = $("#proModalEdit").val();
                }
                menuRule.getProTreeId(pro);
                menuRule.init();
                $("#resetRule").click();
                var oTable2 = new TableInit2();
                oTable2.Init();
                rule.oldRuleDataArr=bs.objArrDeepCopy(tools.ruleTableData);//保存选择前的数据
                $("#addRuleModel").modal('show');
            });
            $("#addRuleBtn").on("click", function () {
                if($(this).attr("data-code")=="editRule"){
                    tools.rootRuleData(tools.ruleTableData, $("#ruleBoxEdit"));
                }else{
                    tools.rootRuleData(tools.ruleTableData, $("#addRuleTable"));
                }
                $("#addRuleModel").modal("hide");
            });
            $(".closeRuleBox").on("click", function () {
                tools.ruleTableData=bs.objArrDeepCopy(rule.oldRuleDataArr);
                tools.rootRuleData(tools.ruleTableData, $("#addRuleTable"));
                tools.rootRuleData(tools.ruleTableData, $("#ruleBoxEdit"));
            });

        },
        addNewRule: function (data) {
            var obj = {};
            obj.id = data.idcombinationrule;//规则id
            obj.ruleid = data.idcombinationrule;//规则id
            obj.ruletypename = data.ruleclassify;//规则分类
            obj.ruletypeid = data.idservice;//规则分类id
            obj.rulename = data.rulename;//规则名称
            obj.userfor = data.ruleattributes;//规则属性
            obj.fateful = data.fatal;//规则致命性
            obj.signscore = data.sign_default_score;//判断加减分
            var default_score=data.default_score;
            obj.scorepertime = default_score;
            obj.maxscore = "";
            if(default_score!=null){
                if (obj.signscore==1) {//判断该字段没有 或者为负数时 是减分 否则加分
                    obj.scorepertime = default_score;
                } else {
                    obj.scorepertime = "-"+default_score;
                }
            }
            return obj;
        },
        delRule: function ($elem) {
            $elem.on("click", ".del", function () {
                var id = $(this).attr("data-id");
                for (var i in tools.ruleTableData) {
                    if (tools.ruleTableData[i].ruleid == id) {
                        tools.ruleTableData.splice(i, 1);
                    }
                }
                tools.rootRuleData(tools.ruleTableData, $elem);
            })
        }
    };
    var validateFun = {
        init: function () {
            this.initKeyValidatorAdd();
            this.initKeyValidatorEdit();
            this.initKeyValidatorAddType();

        },
        initKeyValidatorAdd: function () {
            $("#addModelForm").jqxValidator({
                rules: [
                    {
                        input: '#remarkAdd',
                        message: '最多输入255个字符!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() != "") {
                                if ($(input).val().length > 255) {
                                    result = false
                                }
                            }
                            if (result) {
                                $(input).removeClass("jqx-validator-error-element");
                            }
                            return result;
                        }
                    }, {
                        input: '#proModalAddInput',
                        message: '请选择省份!',
                        action: 'change,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() == "") {
                                result = false
                            }
                            return result;
                        }
                    },
                    {
                        input: '#typeModalAddInput',
                        message: '请选择分类!',
                        action: 'change,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() == "") {
                                result = false
                            }
                            return result;
                        }
                    }

                    , {
                        input: '#testName',
                        message: '质检模型名称不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#testName',
                        message: '质检模型名称不能包含空格!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val().indexOf(" ") > -1) {
                                result = false
                            }
                            return result;
                        }
                    }
                    , {
                        input: '#testName',
                        message: '最多输入' + tools.maxTextLength + '个字符！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() != "") {
                                if ($(input).val().length > 50) {
                                    return false
                                }
                            }
                            return result;
                        }
                    }
                    , {
                        input: '#testScore',
                        message: '质检模型分数不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#testScore',
                        message: '请输入大于等于0、小于等于10000的整数！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var reg = /^[1-9][0-9]{0,3}$|^0$|^10000$/;
                            var val = $.trim($(input).val());
                            if (val != "") {
                                if (!reg.test(val)) {
                                    result = false
                                }
                            }
                            $(input).val(val);
                            return result;
                        },
                        hintRender: function (message, input) {
                            var box = $(input).parent();
                            if (box.find("label").length > 0) {
                                box.find("label").remove();
                            }
                            var label = $("<label class='jqx-validator-error-label' style='width:280px;'>" + message + "</label>");
                            label.appendTo(box);
                            return label
                        }
                    }
                    , {
                        input: '#testName',
                        message: "质检模型名称已经存在!",
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var validate = true;
                            var url = basePath + "rest/model/checkOnly/modelByExample";
                            var data = {
                                name: $(input).val(),
                                provincecode: $("#proModal").val(),
                                typeid: $("#typeModal").val()
                            };
                            $.ajax({
                                url: url,
                                timeout: 10000,
                                async: false,
                                type: 'POST',
                                data: JSON.stringify(data),
                                contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                                success: function (msg) {
                                    if (msg.code < 0) {
                                        input.focus();
                                        validate = false;
                                    }
                                }
                            });
                            return validate;
                        }
                    }
                ],
                hintType: "label"
            });
        },
        initKeyValidatorEdit: function () {
            $("#editForm").jqxValidator({
                rules: [
                    {
                        input: '#remarkEdit',
                        message: '最多输入255个字符!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() != "") {
                                if ($(input).val().length > 255) {
                                    result = false
                                }
                            }
                            if (result) {
                                $(input).removeClass("jqx-validator-error-element");
                            }
                            return result;
                        }
                    }, {
                        input: '#proModalEditInput',
                        message: '请选择省份!',
                        action: 'change,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() == "") {
                                result = false
                            }
                            return result;
                        }
                    },
                    {
                        input: '#typeModalEditInput',
                        message: '请选择分类!',
                        action: 'change,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() == "") {
                                result = false
                            }
                            return result;
                        }
                    }

                    , {
                        input: '#testNameEdit',
                        message: '质检模型名称不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#testNameEdit',
                        message: '质检模型名称不能包含空格!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val().indexOf(" ") > -1) {
                                result = false
                            }
                            return result;
                        }
                    }
                    , {
                        input: '#testNameEdit',
                        message: '最多输入' + tools.maxTextLength + '个字符！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() != "") {
                                if ($(input).val().length > 50) {
                                    return false
                                }
                            }
                            return result;
                        }
                    }
                    , {
                        input: '#testScoreEdit',
                        message: '质检模型分数不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#testScoreEdit',
                        message: '请输入大于等于0、小于等于10000的整数！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var reg = /^[1-9][0-9]{0,3}$|^0$|^10000$/;
                            var val = $.trim($(input).val());
                            if (val != "") {
                                if (!reg.test(val)) {
                                    result = false
                                }
                            }
                            $(input).val(val);
                            return result;
                        },
                        hintRender: function (message, input) {
                            var box = $(input).parent();
                            if (box.find("label").length > 0) {
                                box.find("label").remove();
                            }
                            var label = $("<label class='jqx-validator-error-label' style='width:280px;'>" + message + "</label>");
                            label.appendTo(box);
                            return label
                        }
                    }
                    , {
                        input: '#testNameEdit',
                        message: "质检模型名称已经存在!",
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var validate = true;
                            var url = basePath + "rest/model/checkOnly/modelByExample";
                            var data = {
                                id: $("#editModal").attr("data-id"),
                                name: $(input).val(),
                                provincecode: $("#proModalEdit").val(),
                                typeid: $("#modelTypeEdit").val()
                            };
                            $.ajax({
                                url: url,
                                timeout: 10000,
                                async: false,
                                type: 'POST',
                                data: JSON.stringify(data),
                                contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                                success: function (msg) {
                                    if (msg.code < 0) {
                                        input.focus();
                                        validate = false;
                                    }
                                }
                            });
                            return validate;
                        }
                    }
                ],
                hintType: "label"
            });
        },
        initKeyValidatorAddType: function () {
            $("#addTypeForm").jqxValidator({
                rules: [
                    {
                        input: '#proTypeModalAddInput',
                        message: '请选择省份!',
                        action: 'change,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() == "") {
                                result = false
                            }
                            return result;
                        }
                    }
                    , {
                        input: '#modelTypeName',
                        message: '分类名称不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#modelTypeName',
                        message: '分类名称不能包含空格!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val().indexOf(" ") > -1) {
                                result = false
                            }
                            return result;
                        }
                    }
                    , {
                        input: '#modelTypeName',
                        message: "分类名称已经存在!",
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var validate = true;
                            var isAjax = true;
                            var url = basePath + "rest/model/checkOnly/modelTypeByExample";
                            var code = $("#addTypeModal").attr("data-code");
                            var id = $("#addTypeModal").attr("data-id");
                            var data;
                            if (code == "add") {
                                var ref = $('#jstree').jstree(true);//获得整个树
                                var sel = ref.get_selected(false);
                                data = {
                                    name: $(input).val(),
                                    parentid: sel[0],
                                    provincecode: $("#proTypeModal").val()
                                };
                            } else {
                                var node = $("#jstree").jstree("get_node", id);
                                if (node.text == $(input).val()) {
                                    isAjax = false;
                                }
                                data = {
                                    id: id,
                                    name: $(input).val(),
                                    parentid: node.parent,
                                    provincecode: $("#proTypeModal").val()
                                };
                            }
                            if (isAjax) {
                                $.ajax({
                                    url: url, data: data, timeout: 10000,
                                    async: false, type: 'POST',
                                    success: function (msg) {
                                        if (msg.code < 0) {
                                            input.focus();
                                            validate = false;
                                        }
                                    }
                                });
                            }
                            return validate;
                        }
                    },
                    {
                        input: '#modelTypeName',
                        message: '分类名称不能多余' + tools.maxTextLength + '字！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() != "") {
                                if ($(input).val().length > 50) {
                                    return false
                                }
                            }
                            return result;
                        }
                    },
                    {
                        input: '#remarkTypeAdd',
                        message: '最多输入255个字符!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() != "") {
                                if ($(input).val().length > 255) {
                                    result = false
                                }
                            }
                            if (result) {
                                $(input).removeClass("jqx-validator-error-element");
                            }
                            return result;
                        }
                    }
                ],
                hintType: "label"
            });
        },
        initKeyValidatorCopy: function (elem) {
            $("#copyForm").jqxValidator({
                position: 'right',
                rules: [
                    {
                        input: elem,
                        message: "模型名称已经存在!",
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var validate = true;
                            var url = basePath + "rest/model/checkOnly/modelByExample";
                            var ref = $('#jsTreeCopy').jstree(true);//获得整个树
                            var sel = ref.get_selected(); //获得所有选中节点，返回值为数组
                            var provincecode = $('#jsTreeCopy').jstree("get_node", sel[0]).original.provincecode;
                            if ($(input).val() != "") {
                                var data = {
                                    name: $(input).val(),
                                    provincecode: provincecode,
                                    typeid: parseInt(sel[0])
                                };
                                $.ajax({
                                    url: url,
                                    timeout: 10000,
                                    async: false,
                                    type: 'POST',
                                    data: JSON.stringify(data),
                                    contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                                    success: function (msg) {
                                        if (msg.code < 0) {
                                            validate = false;
                                        }
                                    }
                                });
                                $(input).parent("li").siblings().find("input.newName").each(function () {//与同级的其他几个标签名称比较
                                    if ($(input).val() == $(this).val()) {
                                        validate = false;
                                        return false;//跳出循环
                                    }
                                });
                            }

                            return validate;
                        }
                    },
                    {
                        input: elem,
                        message: '模型名称不能多余' + tools.maxTextLength + '字！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() != "") {
                                if ($(input).val().length > 50) {
                                    return false
                                }
                            }
                            return result;
                        }
                    },
                    {
                        input: elem,
                        message: '模型名称不能包含空格!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val().indexOf(" ") > -1) {
                                result = false
                            }
                            return result;
                        }
                    }, {
                        input: elem,
                        message: '模型名称不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                ]
            });
            $('#copyForm').jqxValidator('updatePosition');
        },
        initValidatorScore: function (form, elem, isValidate) {
            validateFun.destroy(form, elem, isValidate);
            form.jqxValidator({
                position: 'right',
                rules: [
                    {
                        input: elem,
                        message: "分值上限不得小于单次分值!",
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if (isValidate) {
                                var oneScore = parseInt($(input).parents("tr").find(".oneNum").val());
                                if ($(input).val() != "" && oneScore != "") {
                                    if (parseInt($(input).val()) < oneScore) {
                                        result = false;
                                        $(elem).focus();
                                    }
                                }
                            }
                            return result;
                        }
                    },
                    {
                        input: elem,
                        message: '请输入大于等于0、小于等于10000的整数！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var val = $(input).val();
                            var reg = /^[1-9][0-9]{0,3}$|^0$|^10000$/;
                            if ($(input).val() != "") {
                                if (!reg.test(val)) {
                                    result = false;
                                    $(elem).focus();
                                }
                            }
                            return result;
                        }
                    }
                ]
            });
            form.jqxValidator('updatePosition');
        },
        destroy: function (form, elem, isValidate) {
            form.jqxValidator({
                position: 'right',
                rules: []
            });
            form.jqxValidator('updatePosition');
        }
    };
    $(function () {
        var oTable = new TableInit();
        oTable.Init();
        var oTable1 = new TableInit1($('#ruleTable'), json);
        oTable1.Init($('#ruleTable'), json);
        menu.init();
        resize.init();
        tools.init();
        draggables.init();
        rule.init();
        modelType.init();
        validateFun.init();
    })
</script>
</body>
</html>